From b90d62f54676c11766bea5c38a814d607dd0ab6e Mon Sep 17 00:00:00 2001
From: Crozzers
Date: Thu, 18 Jan 2024 18:24:13 +0000
Subject: [PATCH] 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
+