Skip to content

Commit

Permalink
Merge pull request #582 from Crozzers/fcb-and-lists
Browse files Browse the repository at this point in the history
Fix fenced code blocks breaking lists (#580)
  • Loading branch information
nicholasserra committed May 27, 2024
2 parents 5aae144 + d7b6863 commit e7d753f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [pull #576] Fix `html`, `head` and `body` tags being wrapped in `<p>` tags (#575)
- [pull #581] Add type hints (#562)
- [pull #581] Drop Python 3.6 and 3.7 support
- [pull #582] Fix fenced code blocks breaking lists (#580)


## python-markdown2 2.4.13
Expand Down
2 changes: 1 addition & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2872,7 +2872,7 @@ def sub(self, match: re.Match) -> str:

tags = self.tags(lexer_name)

return "\n%s%s%s\n%s\n" % (leading_indent, tags[0], codeblock, tags[1])
return "\n%s%s%s\n%s%s\n" % (leading_indent, tags[0], codeblock, leading_indent, tags[1])

def run(self, text):
return self.fenced_code_block_re.sub(self.sub, text)
Expand Down
13 changes: 13 additions & 0 deletions test/tm-cases/fenced_code_blocks_simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@

<pre><code> is indentation maintained?
</code></pre>

<p>Here's one in a list, with another one following (see #580):</p>

<ul>
<li>List 1
<pre><code>code 1

code 2
</code></pre></li>
</ul>

<pre><code>code 3
</code></pre>
13 changes: 13 additions & 0 deletions test/tm-cases/fenced_code_blocks_simple.text
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@ Here is one at the end of the file:
```
is indentation maintained?
```

Here's one in a list, with another one following (see #580):

* List 1
```
code 1

code 2
```

```
code 3
```

0 comments on commit e7d753f

Please sign in to comment.