Skip to content

Commit

Permalink
Merge pull request #566 from Crozzers/fix-indented-opening-tag-causin…
Browse files Browse the repository at this point in the history
…g-crashes

Fix crash in `markdown-in-html` extra (#565)
  • Loading branch information
nicholasserra committed Jan 23, 2024
2 parents 1c7902b + 3d6ecca commit 749ee72
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -5,6 +5,7 @@
- [pull #559] Allow cuddled tables (#557)
- [pull #560] Fix `markdown-in-html` not always splitting HTML tags into separate lines (#558)
- [pull #564] Fix incomplete comments in safe mode not being escaped (#563)
- [pull #566] Fix crash in `markdown-in-html` extra (#565)


## python-markdown2 2.4.12
Expand Down
6 changes: 3 additions & 3 deletions lib/markdown2.py
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*?</%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
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
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 749ee72

Please sign in to comment.