From 07ed12955b5e1ca1c26435537c014cfd74dbd0f6 Mon Sep 17 00:00:00 2001 From: facelessuser Date: Sat, 2 Sep 2023 11:58:13 -0600 Subject: [PATCH 1/2] 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 --- docs/changelog.md | 7 +++++++ markdown/extensions/admonition.py | 2 +- .../test_syntax/extensions/test_admonition.py | 20 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index d233abfda..24f549a80 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -28,6 +28,13 @@ 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). +## [3.4.5] -- ????-??-?? + +### Fixed + +* Fix a corner case in admonitions where if an indented code block was provided + as the first block, the output would be malformed. + ## [3.4.4] -- 2023-07-25 ### Fixed diff --git a/markdown/extensions/admonition.py b/markdown/extensions/admonition.py index ce8492f4a..0d1250fc9 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 44c70d14c..268633ddf 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'] + ) From c1c824ec3fac0d3e6ac6ad9a6716a8d9513d6bb8 Mon Sep 17 00:00:00 2001 From: facelessuser Date: Tue, 5 Sep 2023 07:50:32 -0600 Subject: [PATCH 2/2] Update changelog --- docs/changelog.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 24f549a80..50e868c32 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -28,12 +28,10 @@ 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). -## [3.4.5] -- ????-??-?? - ### Fixed * Fix a corner case in admonitions where if an indented code block was provided - as the first block, the output would be malformed. + as the first block, the output would be malformed (#1329). ## [3.4.4] -- 2023-07-25