diff --git a/docs/changelog.md b/docs/changelog.md index d233abfd..50e868c3 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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 diff --git a/markdown/extensions/admonition.py b/markdown/extensions/admonition.py index ce8492f4..0d1250fc 100644 --- a/markdown/extensions/admonition.py +++ b/markdown/extensions/admonition.py @@ -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 diff --git a/tests/test_syntax/extensions/test_admonition.py b/tests/test_syntax/extensions/test_admonition.py index 44c70d14..268633dd 100644 --- a/tests/test_syntax/extensions/test_admonition.py +++ b/tests/test_syntax/extensions/test_admonition.py @@ -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( + ''' +
+

This is not

+
one long admonition title
+                
+
+ ''' + ), + extensions=['admonition'] + )