diff --git a/CHANGES.md b/CHANGES.md index 4aee683e..c6b1df5e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/lib/markdown2.py b/lib/markdown2.py index 50d97215..7f55b458 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -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 '' % 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: @@ -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('' % tag_name, text)) + def _strip_link_definitions(self, text): # Strips link definitions from text, stores the URLs and titles in # hash references. diff --git a/test/tm-cases/hash_html_blocks_issue_508.html b/test/tm-cases/hash_html_blocks_issue_508.html new file mode 100644 index 00000000..2c176c15 --- /dev/null +++ b/test/tm-cases/hash_html_blocks_issue_508.html @@ -0,0 +1,12 @@ +
+
+ +
+ +
+ +
+ + diff --git a/test/tm-cases/hash_html_blocks_issue_508.text b/test/tm-cases/hash_html_blocks_issue_508.text new file mode 100644 index 00000000..dbe7342d --- /dev/null +++ b/test/tm-cases/hash_html_blocks_issue_508.text @@ -0,0 +1,7 @@ +
+
+
+
+
+ +- A