Skip to content

Commit eee3032

Browse files
committed
Ensure nested elements inside inline comments are properly unescaped.
When inline Markdwon elements are nested, each nested level contains its own placeholder. Therefore, when unescaping, the regex substitution needs to be run again each nested level. As this is nested inside the match, it ensures only one non-matching regex will be run in each instace. Closes #1571.
1 parent 22e89c1 commit eee3032

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

markdown/inlinepatterns.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ def get_stash(m: re.Match[str]) -> str:
520520
value = stash.get(id)
521521
if value is not None:
522522
try:
523-
return self.md.serializer(value)
523+
# Ensure we don't have a placeholder inside a placeholder
524+
return self.unescape(self.md.serializer(value))
524525
except Exception:
525526
return r'\%s' % value
526527

tests/test_syntax/inline/test_raw_html.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ def test_inline_html_backslashes(self):
3434

3535
def test_noname_tag(self):
3636
self.assertMarkdownRenders('<span></></span>', '<p><span>&lt;/&gt;</span></p>')
37+
38+
def test_markdown_nested_in_inline_comment(self):
39+
self.assertMarkdownRenders(
40+
'Example: <!-- [**Bold link**](http://example.com) -->',
41+
'<p>Example: <!-- <a href="http://example.com"><strong>Bold link</strong></a> --></p>'
42+
)

0 commit comments

Comments
 (0)