Skip to content
This repository has been archived by the owner on Oct 27, 2023. It is now read-only.

Commit

Permalink
Fix admonition corner case with indented code blocks
Browse files Browse the repository at this point in the history
Fix a corner case in admonitions where if an indented code block was
provided as the first block, the output would be malformed.

Fixes Python-Markdown#1329.
  • Loading branch information
facelessuser authored Sep 5, 2023
1 parent 25b64df commit 5a2fee3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ links to the header, placing them after all other header content.
* Update the list of empty HTML tags (#1353).
* Add customizable TOC title class to TOC extension (#1293).

### Fixed

* Fix a corner case in admonitions where if an indented code block was provided
as the first block, the output would be malformed (#1329).

## [3.4.4] -- 2023-07-25

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion markdown/extensions/admonition.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def parse_content(self, parent, block):

sibling = self.lastChild(parent)

if sibling is None or sibling.get('class', '').find(self.CLASSNAME) == -1:
if sibling is None or sibling.tag != 'div' or sibling.get('class', '').find(self.CLASSNAME) == -1:
sibling = None
else:
# If the last child is a list and the content is sufficiently indented
Expand Down
20 changes: 20 additions & 0 deletions tests/test_syntax/extensions/test_admonition.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,23 @@ def test_admontion_detabbing(self):
),
extensions=['admonition']
)

def test_admonition_first_indented(self):
self.assertMarkdownRenders(
self.dedent(
'''
!!! danger "This is not"
one long admonition title
'''
),
self.dedent(
'''
<div class="admonition danger">
<p class="admonition-title">This is not</p>
<pre><code>one long admonition title
</code></pre>
</div>
'''
),
extensions=['admonition']
)

0 comments on commit 5a2fee3

Please sign in to comment.