From c9391257691e9ef895e1e6894cd61a8dfdf232fa Mon Sep 17 00:00:00 2001 From: Crozzers Date: Wed, 26 Apr 2023 22:05:43 +0100 Subject: [PATCH 1/3] Fix #508 --- lib/markdown2.py | 6 +++++- test/tm-cases/hash_html_blocks_issue_508.html | 8 ++++++++ test/tm-cases/hash_html_blocks_issue_508.text | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/tm-cases/hash_html_blocks_issue_508.html create mode 100644 test/tm-cases/hash_html_blocks_issue_508.text 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..f39d91a5 --- /dev/null +++ b/test/tm-cases/hash_html_blocks_issue_508.html @@ -0,0 +1,8 @@ +
+
+ +
+ +
+ +
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..56755712 --- /dev/null +++ b/test/tm-cases/hash_html_blocks_issue_508.text @@ -0,0 +1,5 @@ +
+
+
+
+
From e0fea567c7947dd9ddee870fa56003b212a31b74 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Wed, 26 Apr 2023 22:09:25 +0100 Subject: [PATCH 2/3] Update #508 test --- test/tm-cases/hash_html_blocks_issue_508.html | 4 ++++ test/tm-cases/hash_html_blocks_issue_508.text | 2 ++ 2 files changed, 6 insertions(+) diff --git a/test/tm-cases/hash_html_blocks_issue_508.html b/test/tm-cases/hash_html_blocks_issue_508.html index f39d91a5..2c176c15 100644 --- a/test/tm-cases/hash_html_blocks_issue_508.html +++ b/test/tm-cases/hash_html_blocks_issue_508.html @@ -6,3 +6,7 @@
+ + diff --git a/test/tm-cases/hash_html_blocks_issue_508.text b/test/tm-cases/hash_html_blocks_issue_508.text index 56755712..dbe7342d 100644 --- a/test/tm-cases/hash_html_blocks_issue_508.text +++ b/test/tm-cases/hash_html_blocks_issue_508.text @@ -3,3 +3,5 @@
+ +- A From e2c1c6467591a5f96cdf5497e8f28d3858602795 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Wed, 26 Apr 2023 22:13:56 +0100 Subject: [PATCH 3/3] Update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) 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