Repository navigation
Fix fenced code blocks ending early at a line ending with backticks - #760
Open
nk-batman21 wants to merge 1 commit into
Open
nk-batman21 wants to merge 1 commit into
nk-batman21 wants to merge 1 commit into
Conversation
The closing fence pattern was not anchored to the start of a line, so any line inside a fenced code block that ended with the opening fence closed the block there. A Python docstring with an indented ``` example split the block, and the rest of the document swapped code and text. Require the closing fence to start a line again, as it did before pull trentm#418. Allow it to be indented up to three more spaces than the opening fence and to be longer than it, which already closed a block.
nk-batman21
force-pushed
the
fix-fenced-code-closing-fence
branch
from
November 2, 2026 19:30
ae58cfe to
af18068
Compare
Collaborator
|
Looks reasonable, merge master in or rebase and should be able to merge if passes CI thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the
fenced-code-blocksextra, a line inside a code block that ends with the opening backticks closes the block there, wherever the backticks sit on the line. This happens whenever the code itself contains a Markdown fence, for example a Python function whose docstring has an indented example:On master the block ends at the indented
```line.greet()becomes a separate code block, the real closing fence then opens a new block that swallows "Some text between the blocks.", and code and prose swap places for the rest of the document. A code line such asWrap code in ```does the same.This is a regression from #418, which changed the closing fence from
^```[ \t]*\nto\1[ \t]*\nand dropped the^. This puts the anchor back and lets the closing fence be indented up to 3 more spaces than the opening fence or be longer than it. Both of those already closed a block by matching partway through the line, and they no longer leave a stray whitespace or blank line at the end of the code. A closing fence indented 4 or more spaces past the opening one no longer closes the block, as in CommonMark.Ran:
make testoneon Python 3.9 to 3.14 (304 tests pass) andmake testredos; the new fixture fails without the change.Checked: the docstring example is fixed with Pygments,
highlightjs-langand safe mode too. Fences inside list items, blockquotes, footnotes and admonitions render as before, and the nested fences from #327 still work.