From b90d62f54676c11766bea5c38a814d607dd0ab6e Mon Sep 17 00:00:00 2001
From: Crozzers
Date: Thu, 18 Jan 2024 18:24:13 +0000
Subject: [PATCH 1/3] Fix opening HTML tag causing occasionally crashes when
`markdown-in-html` enabled
---
lib/markdown2.py | 6 +++---
test/tm-cases/markdown_in_html_in_lists.html | 16 ++++++++++++++++
test/tm-cases/markdown_in_html_in_lists.text | 11 +++++++++++
3 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/lib/markdown2.py b/lib/markdown2.py
index 28cf4f40..41e408d0 100755
--- a/lib/markdown2.py
+++ b/lib/markdown2.py
@@ -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)
@@ -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])
diff --git a/test/tm-cases/markdown_in_html_in_lists.html b/test/tm-cases/markdown_in_html_in_lists.html
index 981113f9..18ae6bf3 100644
--- a/test/tm-cases/markdown_in_html_in_lists.html
+++ b/test/tm-cases/markdown_in_html_in_lists.html
@@ -34,4 +34,20 @@ Block three
+
+
+one two
+
+
+
+
NOTE: opening tag is slightly indented
+
+
+three four
+
+
+
+
NOTE: both tags are slightly indented
+
+
diff --git a/test/tm-cases/markdown_in_html_in_lists.text b/test/tm-cases/markdown_in_html_in_lists.text
index e629c55d..22121126 100644
--- a/test/tm-cases/markdown_in_html_in_lists.text
+++ b/test/tm-cases/markdown_in_html_in_lists.text
@@ -15,3 +15,14 @@
###### Block three
Some text
+
+
+
+- one two
+
+ *NOTE:* opening tag is slightly indented
+
+- three four
+
+ *NOTE:* both tags are slightly indented
+
From 92eb442d4c2caf35136d4e32d340030da4d06f41 Mon Sep 17 00:00:00 2001
From: Crozzers
Date: Thu, 18 Jan 2024 18:59:13 +0000
Subject: [PATCH 2/3] Update changelog
---
CHANGES.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGES.md b/CHANGES.md
index 56de6256..fc66cf3a 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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
From 3d6ecca7e0e033fedf867818202cbc1368bc64c3 Mon Sep 17 00:00:00 2001
From: Crozzers
Date: Thu, 18 Jan 2024 19:07:34 +0000
Subject: [PATCH 3/3] Fix failing test cases
---
lib/markdown2.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/markdown2.py b/lib/markdown2.py
index 41e408d0..4d000984 100755
--- a/lib/markdown2.py
+++ b/lib/markdown2.py
@@ -803,7 +803,7 @@ def _hash_html_block_sub(self, match, raw=False):
# 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:]
# 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])