Skip to content

Commit 5a2fee3

Browse files
authored
Fix admonition corner case with indented code blocks
Fix a corner case in admonitions where if an indented code block was provided as the first block, the output would be malformed. Fixes #1329.
1 parent 25b64df commit 5a2fee3

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

docs/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ links to the header, placing them after all other header content.
2828
* Update the list of empty HTML tags (#1353).
2929
* Add customizable TOC title class to TOC extension (#1293).
3030

31+
### Fixed
32+
33+
* Fix a corner case in admonitions where if an indented code block was provided
34+
as the first block, the output would be malformed (#1329).
35+
3136
## [3.4.4] -- 2023-07-25
3237

3338
### Fixed

markdown/extensions/admonition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def parse_content(self, parent, block):
6969

7070
sibling = self.lastChild(parent)
7171

72-
if sibling is None or sibling.get('class', '').find(self.CLASSNAME) == -1:
72+
if sibling is None or sibling.tag != 'div' or sibling.get('class', '').find(self.CLASSNAME) == -1:
7373
sibling = None
7474
else:
7575
# If the last child is a list and the content is sufficiently indented

tests/test_syntax/extensions/test_admonition.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,23 @@ def test_admontion_detabbing(self):
243243
),
244244
extensions=['admonition']
245245
)
246+
247+
def test_admonition_first_indented(self):
248+
self.assertMarkdownRenders(
249+
self.dedent(
250+
'''
251+
!!! danger "This is not"
252+
one long admonition title
253+
'''
254+
),
255+
self.dedent(
256+
'''
257+
<div class="admonition danger">
258+
<p class="admonition-title">This is not</p>
259+
<pre><code>one long admonition title
260+
</code></pre>
261+
</div>
262+
'''
263+
),
264+
extensions=['admonition']
265+
)

0 commit comments

Comments
 (0)