Skip to content

Commit

Permalink
Merge pull request #578 from edufresne/master
Browse files Browse the repository at this point in the history
Graceful handling of broken lists when cuddled-lists extra is enabled
  • Loading branch information
nicholasserra authored May 27, 2024
2 parents e0baec2 + 4684839 commit 1518457
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2181,8 +2181,13 @@ def _form_paragraphs(self, text):
):
start = li.start()
cuddled_list = self._do_lists(graf[start:]).rstrip("\n")
assert re.match(r'^<(?:ul|ol).*?>', cuddled_list)
graf = graf[:start]
if re.match(r'^<(?:ul|ol).*?>', cuddled_list):
graf = graf[:start]
else:
# Not quite a cuddled list. (See not_quite_a_list_cuddled_lists test case)
# Store as a simple paragraph.
graf = cuddled_list
cuddled_list = None

# Wrap <p> tags.
graf = self._run_span_gamut(graf)
Expand Down
26 changes: 26 additions & 0 deletions test/tm-cases/not_quite_a_list_cuddled_lists.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<p>So:</p>

<ul>
<li>This</li>
<li>is</li>
<li>a list.</li>
</ul>

<p>And:</p>

<ul>
<li><em>This</em> is</li>
<li>a list</li>
<li>too.</li>
</ul>

<p>However, because ASCII art can have long dash/asterisk lines let ensure that:</p>

<p>- - - - - - - This isn't a list.</p>

<p>* * Nor is this a list.
- - - Or this.</p>

<p>- - - - - - - - - - +
hi there ascii art
- - - - - - - - - - +</p>
1 change: 1 addition & 0 deletions test/tm-cases/not_quite_a_list_cuddled_lists.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"extras": ["cuddled-lists"]}
21 changes: 21 additions & 0 deletions test/tm-cases/not_quite_a_list_cuddled_lists.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
So:
- This
- is
- a list.

And:
* *This* is
* a list
* too.

However, because ASCII art can have long dash/asterisk lines let ensure that:

- - - - - - - This isn't a list.

* * Nor is this a list.
- - - Or this.


- - - - - - - - - - +
hi there ascii art
- - - - - - - - - - +

0 comments on commit 1518457

Please sign in to comment.