Skip to content

Fix code block parsing error (issue #327) - #418

Merged
nicholasserra merged 1 commit into
trentm:masterfrom
Crozzers:fix-issue-327
Mar 14, 2022
Merged

nicholasserra merged 1 commit into
trentm:masterfrom
Crozzers:fix-issue-327

Conversation

@Crozzers

@Crozzers Crozzers commented Mar 10, 2022 •

Copy link
Copy Markdown
Contributor

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 :

````
```cpp
int x = 10;
```
````

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.Match that gets passed to _code_block_sub

@Crozzers Crozzers changed the title Fix issue 327 Fix code block parsing error (issue #327) Mar 11, 2022
@nicholasserra

Copy link
Copy Markdown
Collaborator

Nice thank you

@nicholasserra
nicholasserra merged commit 8b18ebd into trentm:master Mar 14, 2022
@Crozzers
Crozzers deleted the fix-issue-327 branch March 16, 2022 13:03
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants