Skip to content

Commit 5d91369

Browse files
committed
Issue Python-Markdown#368: Fix Markdown in raw HTML stops working
Originally there was an infinite loop issue that was patched in issue Python-Markdown#308. Unfortunately, it was fixed all the way. This fix patches the infinite loop fix to only add an offset to the `right_listindex` when it is in a infinite loop scenario.
1 parent 69fd8b4 commit 5d91369

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

markdown/preprocessors.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,10 @@ def _nested_markdown_in_html(self, items):
174174
else: # raw html
175175
if len(items) - right_listindex <= 1: # last element
176176
right_listindex -= 1
177+
offset = 1 if i == right_listindex else 0
177178
placeholder = self.markdown.htmlStash.store('\n\n'.join(
178-
items[i:right_listindex + 1]))
179-
del items[i:right_listindex + 1]
179+
items[i:right_listindex + offset]))
180+
del items[i:right_listindex + offset]
180181
items.insert(i, placeholder)
181182
return items
182183

tests/extensions/extra/raw-html.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@
2727
Raw html blocks may also be nested.
2828
</div>
2929

30-
31-
3230
</div>
3331
<p>This text is after the markdown in html.</p>
3432
<div name="issue308">
3533
<p><span>1</span>
3634
<span>2</span></p>
37-
</div>
35+
</div>
36+
<div name="issue368">
37+
<p>Markdown is <em>active</em> here.</p>
38+
<div name="RawHtml">
39+
Raw html blocks may also be nested.
40+
</div>
41+
42+
<p>Markdown is <em>still</em> active here.</p>
43+
</div>
44+
<p>Markdown is <em>active again</em> here.</p>

tests/extensions/extra/raw-html.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,17 @@ This text is after the markdown in html.
5151
<span>2</span>
5252

5353
</div>
54+
55+
<div markdown="1" name="issue368">
56+
57+
Markdown is *active* here.
58+
59+
<div name="RawHtml">
60+
Raw html blocks may also be nested.
61+
</div>
62+
63+
Markdown is *still* active here.
64+
65+
</div>
66+
67+
Markdown is *active again* here.

0 commit comments

Comments
 (0)