Repository navigation
Fix code block parsing error (issue #327) - #418
Merged
Merged
Conversation
Collaborator
|
Nice thank you |
nk-batman21
added a commit
to nk-batman21/python-markdown2
that referenced
this pull request
Nov 2, 2026
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
added a commit
to nk-batman21/python-markdown2
that referenced
this pull request
Nov 7, 2026
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.
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.
As stated in issue #327, Markdown allows for inserting fenced code blocks within other fenced code blocks, provided that the outer code block has one more back-tick than the inner one.
EG :
The previous regex for fenced code blocks would look for lines starting with three back-ticks only. The new regex checks for lines starting with three or more back-ticks and then uses a back reference to find an identical closing set of back-ticks.
The disadvantage of this is that the opening back-ticks have to be captured for the back reference to work, which makes it the first group of the
re.Matchthat gets passed to_code_block_sub