From 12be7c9a30247b1df9a211a4cc90dfb9aa136fae Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Wed, 30 Dec 2020 15:09:46 +0100 Subject: [PATCH] Preserve text immediately before an admonition --- docs/change_log/index.md | 1 + markdown/extensions/admonition.py | 2 ++ .../test_syntax/extensions/test_admonition.py | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/docs/change_log/index.md b/docs/change_log/index.md index 90ed1a30a..b9a1a9000 100644 --- a/docs/change_log/index.md +++ b/docs/change_log/index.md @@ -8,6 +8,7 @@ Under development: version 3.3.4 (a bug-fix release). * Properly parse unclosed tags in code spans (#1066). * Properly parse processing instructions in md_in_html (#1070). * Properly parse code spans in md_in_html (#1069). +* Preserve text immediately before an admonition (#1092). * Simplified regex for HTML placeholders (#928) addressing (#932). Oct 25, 2020: version 3.3.3 (a bug-fix release). diff --git a/markdown/extensions/admonition.py b/markdown/extensions/admonition.py index 01f994010..916d9318b 100644 --- a/markdown/extensions/admonition.py +++ b/markdown/extensions/admonition.py @@ -113,6 +113,8 @@ def run(self, parent, blocks): m = self.RE.search(block) if m: + if m.start() > 0: + self.parser.parseBlocks(parent, [block[:m.start()]]) block = block[m.end():] # removes the first line else: sibling, block = self.get_sibling(parent, block) diff --git a/tests/test_syntax/extensions/test_admonition.py b/tests/test_syntax/extensions/test_admonition.py index 39be9978e..b8d4f06e3 100644 --- a/tests/test_syntax/extensions/test_admonition.py +++ b/tests/test_syntax/extensions/test_admonition.py @@ -192,3 +192,24 @@ def test_definition_list(self): ), extensions=['admonition', 'def_list'] ) + + def test_with_preceding_text(self): + self.assertMarkdownRenders( + self.dedent( + ''' + foo + **foo** + !!! note "Admonition" + ''' + ), + self.dedent( + ''' +

foo + foo

+
+

Admonition

+
+ ''' + ), + extensions=['admonition'] + )