Skip to content

Commit 12be7c9

Browse files
authored
Preserve text immediately before an admonition
1 parent 4b83620 commit 12be7c9

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

docs/change_log/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Under development: version 3.3.4 (a bug-fix release).
88
* Properly parse unclosed tags in code spans (#1066).
99
* Properly parse processing instructions in md_in_html (#1070).
1010
* Properly parse code spans in md_in_html (#1069).
11+
* Preserve text immediately before an admonition (#1092).
1112
* Simplified regex for HTML placeholders (#928) addressing (#932).
1213

1314
Oct 25, 2020: version 3.3.3 (a bug-fix release).

markdown/extensions/admonition.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def run(self, parent, blocks):
113113
m = self.RE.search(block)
114114

115115
if m:
116+
if m.start() > 0:
117+
self.parser.parseBlocks(parent, [block[:m.start()]])
116118
block = block[m.end():] # removes the first line
117119
else:
118120
sibling, block = self.get_sibling(parent, block)

tests/test_syntax/extensions/test_admonition.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,24 @@ def test_definition_list(self):
192192
),
193193
extensions=['admonition', 'def_list']
194194
)
195+
196+
def test_with_preceding_text(self):
197+
self.assertMarkdownRenders(
198+
self.dedent(
199+
'''
200+
foo
201+
**foo**
202+
!!! note "Admonition"
203+
'''
204+
),
205+
self.dedent(
206+
'''
207+
<p>foo
208+
<strong>foo</strong></p>
209+
<div class="admonition note">
210+
<p class="admonition-title">Admonition</p>
211+
</div>
212+
'''
213+
),
214+
extensions=['admonition']
215+
)

0 commit comments

Comments
 (0)