Skip to content

Commit

Permalink
Fix opening HTML tag causing occasionally crashes when `markdown-in-h…
Browse files Browse the repository at this point in the history
…tml` enabled
  • Loading branch information
Crozzers committed Jan 18, 2024
1 parent 1c7902b commit b90d62f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def _hash_html_block_sub(self, match, raw=False):
except IndexError:
tag = None

tag = tag or re.match(r'^<(\S).*?>', html).group(1)
tag = tag or re.match(r'.*?<(\S).*?>', html).group(1)

if raw and self.safe_mode:
html = self._sanitize_html(html)
Expand All @@ -801,9 +801,9 @@ def _hash_html_block_sub(self, match, raw=False):
if m:
lines = html.split('\n')
# if MD is on same line as opening tag then split across two lines
lines = list(filter(None, (re.split(r'(<%s.*markdown=.*?>)' % tag, lines[0])))) + lines[1:]
lines = list(filter(None, (re.split(r'(.*?<%s.*markdown=.*?>)' % tag, lines[0])))) + lines[1:]
# if MD on same line as closing tag, split across two lines
lines = lines[:-1] + list(filter(None, re.split(r'(</%s>.*?$)' % tag, lines[-1])))
lines = lines[:-1] + list(filter(None, re.split(r'(.*?</%s>.*?$)' % tag, lines[-1])))
# extract key sections of the match
first_line = lines[0]
middle = '\n'.join(lines[1:-1])
Expand Down
16 changes: 16 additions & 0 deletions test/tm-cases/markdown_in_html_in_lists.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,20 @@ <h6>Block three</h6>

</div></li>
</ul></li>


<li><p>one two</p>

<p>

<p><em>NOTE:</em> opening tag is slightly indented</p>

</p></li>
<li><p>three four</p>

<p>

<p><em>NOTE:</em> both tags are slightly indented</p>

</p></li>
</ul>
11 changes: 11 additions & 0 deletions test/tm-cases/markdown_in_html_in_lists.text
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@
###### Block three
Some text
</div>



- one two
<p markdown="1">
*NOTE:* opening tag is slightly indented
</p>
- three four
<p markdown="1">
*NOTE:* both tags are slightly indented
</p>

0 comments on commit b90d62f

Please sign in to comment.