Skip to content

Commit

Permalink
Merge pull request #509 from Crozzers/fix-issue-508
Browse files Browse the repository at this point in the history
Fix HTML elements not unhashing correctly (issue 508)
  • Loading branch information
nicholasserra committed Apr 28, 2023
2 parents bce3f18 + e2c1c64 commit 4cf766c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -6,6 +6,7 @@
- [pull #501] Fix link patterns extra matching against internal hashes
- [pull #502] Replace deprecated `optparse` with `argparse`
- [pull #506] Fix `_uniform_outdent` failing with empty strings (issue #505)
- [pull #509] Fix HTML elements not unhashing correctly (issue 508)


## python-markdown2 2.4.8
Expand Down
6 changes: 5 additions & 1 deletion lib/markdown2.py
Expand Up @@ -890,7 +890,7 @@ def _strict_tag_block_sub(self, text, html_tags_re, callback):
tag_count -= 1
else:
# if close tag is in same line
if '</%s>' % is_markup.group(2) in chunk[is_markup.end():]:
if self._tag_is_closed(is_markup.group(2), chunk):
# we must ignore these
is_markup = None
else:
Expand All @@ -908,6 +908,10 @@ def _strict_tag_block_sub(self, text, html_tags_re, callback):

return result

def _tag_is_closed(self, tag_name, text):
# super basic check if number of open tags == number of closing tags
return len(re.findall('<%s(?:.*?)>' % tag_name, text)) == len(re.findall('</%s>' % tag_name, text))

def _strip_link_definitions(self, text):
# Strips link definitions from text, stores the URLs and titles in
# hash references.
Expand Down
12 changes: 12 additions & 0 deletions test/tm-cases/hash_html_blocks_issue_508.html
@@ -0,0 +1,12 @@
<div><div></div>
</div>

<div></div>

<div></div>

<div></div>

<ul>
<li>A</li>
</ul>
7 changes: 7 additions & 0 deletions test/tm-cases/hash_html_blocks_issue_508.text
@@ -0,0 +1,7 @@
<div><div></div>
</div>
<div></div>
<div></div>
<div></div>

- A

0 comments on commit 4cf766c

Please sign in to comment.