Skip to content

Codefences closing improperly when inside GFM alert quotes blocks #1141

Closed

Description

@TendTo

What version of myst-parser are you using?

5.1.0

What version dependencies are you using?

  • Sphinx : 9.1.0
  • docutils: 0.22.4

What operating system are you using?

Linux

Describe the Bug

It seems that, when using GitHub alerts as admonitions, codefences blocks misbehave.
More specifically, they do not close correctly.

Expected Behavior

Nesting GFM alerts and codefences works as on GitHub and coherently with nesting codefences with other quote blocks (not adminitions).

To Reproduce

Examples

Try rendering the following snippet:

  This works:
  
  :::{note}
  Tip
  
  ```py
  "code"
  ```
  
  other
  
  ```py
  "other code"
  ```
  
  :::
  
  but this doesn't
  
  > [!NOTE]  
  > Note
  >
  > ```py
  > "code"
  > ```
  >
  > other
  >
  > ```py
  > "other code"
  > ```
  
  More in general, there is an issue with code fences not closing correctly, e.g.,
  
  > [!NOTE]  
  > Note
  >
  > ```py
  > code
  > ```
  
  For some reason the code fence extends here too, and stops only at the end of the next code fence.
  
  ```py
  "other code"
  ```
  
  Now I'm finally outside the code fence!
  
  The issue only seems to affect admonitions, as regular quotes work fine:
  
  > Quote (but not an admonition)
  >
  > ```py
  > "code"
  > ```
  >
  > other
  >
  > ```py
  > "other code"
  > ```
  
  and then we are out.

GirHub rendering for reference

This works:

:::{note}
Tip

"code"

other

"other code"

:::

but this doesn't

Note

Note

"code"

other

"other code"

More in general, there is an issue with code fences not closing correctly, e.g.,

Note

Note

code

For some reason the code fence extends here too, and stops only at the end of the next code fence.

"other code"

Now I'm finally outside the code fence!

The issue only seems to affect admonitions, as regular quotes work fine:

Quote (but not an admonition)

"code"

other

"other code"

and then we are out.

Activity

  1. chrisjsewell commented on May 20, 2026

    @chrisjsewell
    Member

    I just added a reproducer (I believe) upstream, and this seems to be working there: executablebooks/markdown-it-py#398

  2. TendTo commented on May 20, 2026

    @TendTo
    Author

    I would suggest making the content of the block quote longer, something like

    > [!NOTE]  
    >
    > Note
    >
    > ```py
    > "code"
    > ```
    >
    > other
    >
    > ```py
    > "other code"
    > ```
    

    because, if it only contains a single fenced block, it seems it works, provided nothing else follows.

  3. chrisjsewell commented on Jul 12, 2026

    @chrisjsewell
    Member

    The underlying bug was fixed upstream in markdown-it-py 4.2.0 (already the minimum version required here), and #1142 has now added a regression test covering code fences inside GFM alerts, so closing.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions