Skip to content

Commit 4684839

Browse files
author
edufresne
committed
Graceful handling of broken lists when cuddled-lists extra is enabled
1 parent e0baec2 commit 4684839

4 files changed

+55
-2
lines changed

lib/markdown2.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -2181,8 +2181,13 @@ def _form_paragraphs(self, text):
21812181
):
21822182
start = li.start()
21832183
cuddled_list = self._do_lists(graf[start:]).rstrip("\n")
2184-
assert re.match(r'^<(?:ul|ol).*?>', cuddled_list)
2185-
graf = graf[:start]
2184+
if re.match(r'^<(?:ul|ol).*?>', cuddled_list):
2185+
graf = graf[:start]
2186+
else:
2187+
# Not quite a cuddled list. (See not_quite_a_list_cuddled_lists test case)
2188+
# Store as a simple paragraph.
2189+
graf = cuddled_list
2190+
cuddled_list = None
21862191

21872192
# Wrap <p> tags.
21882193
graf = self._run_span_gamut(graf)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<p>So:</p>
2+
3+
<ul>
4+
<li>This</li>
5+
<li>is</li>
6+
<li>a list.</li>
7+
</ul>
8+
9+
<p>And:</p>
10+
11+
<ul>
12+
<li><em>This</em> is</li>
13+
<li>a list</li>
14+
<li>too.</li>
15+
</ul>
16+
17+
<p>However, because ASCII art can have long dash/asterisk lines let ensure that:</p>
18+
19+
<p>- - - - - - - This isn't a list.</p>
20+
21+
<p>* * Nor is this a list.
22+
- - - Or this.</p>
23+
24+
<p>- - - - - - - - - - +
25+
hi there ascii art
26+
- - - - - - - - - - +</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"extras": ["cuddled-lists"]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
So:
2+
- This
3+
- is
4+
- a list.
5+
6+
And:
7+
* *This* is
8+
* a list
9+
* too.
10+
11+
However, because ASCII art can have long dash/asterisk lines let ensure that:
12+
13+
- - - - - - - This isn't a list.
14+
15+
* * Nor is this a list.
16+
- - - Or this.
17+
18+
19+
- - - - - - - - - - +
20+
hi there ascii art
21+
- - - - - - - - - - +

0 commit comments

Comments
 (0)