Skip to content

Commit

Permalink
fix list parsing edge case
Browse files Browse the repository at this point in the history
Fix an incorrect list parsing (text merged) in situation like:

```
foo
- bar

table
```

which output:

```
<p>foo<br />
table</p>
<ul>
<li>bar</li>
</ul>
```

instead of:

```
<p>foo</p>
<ul>
<li>bar</li>
</ul>
<p>table</p>
```

The "table" is wrongly matched by `BLOCK_HTML` specification due to
the use of `_BLOCK_TAGS_PATTERN` without parens.

All text begins with what's in `BLOCK_TAGS` will have this issue.
  • Loading branch information
fans656 committed Mar 29, 2024
1 parent 29d3120 commit bb3374d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mistune/block_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
_LINE_BLANK_END = re.compile(r'\n[ \t]*\n$')
_BLANK_TO_LINE = re.compile(r'[ \t]*\n')

_BLOCK_TAGS_PATTERN = '|'.join(BLOCK_TAGS) + '|' + '|'.join(PRE_TAGS)
_BLOCK_TAGS_PATTERN = '(' + '|'.join(BLOCK_TAGS) + '|' + '|'.join(PRE_TAGS) + ')'
_OPEN_TAG_END = re.compile(HTML_ATTRIBUTES + r'[ \t]*>[ \t]*(?:\n|$)')
_CLOSE_TAG_END = re.compile(r'[ \t]*>[ \t]*(?:\n|$)')
_STRICT_BLOCK_QUOTE = re.compile(r'( {0,3}>[^\n]*(?:\n|$))+')
Expand Down
6 changes: 6 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ def test_emsp(self):
result = md('\u2003\u2003foo\nbar\n\n\u2003\u2003foobar')
expected = '<p>\u2003\u2003foo<br />\nbar</p>\n<p>\u2003\u2003foobar</p>'
self.assertEqual(result.strip(), expected)

def test_html_tag_text_following_list(self):
md = mistune.create_markdown(escape=False, hard_wrap=True)
result = md('foo\n- bar\n\ntable')
expected = '<p>foo</p>\n<ul>\n<li>bar</li>\n</ul>\n<p>table</p>'
self.assertEqual(result.strip(), expected)

0 comments on commit bb3374d

Please sign in to comment.