From eee30321e3b1dc6df2d5cdd871670dfa71fed2c4 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Mon, 1 Dec 2025 09:39:02 -0500 Subject: [PATCH 1/3] 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. --- markdown/inlinepatterns.py | 3 ++- tests/test_syntax/inline/test_raw_html.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py index 13b3c35f8..9f24512bf 100644 --- a/markdown/inlinepatterns.py +++ b/markdown/inlinepatterns.py @@ -520,7 +520,8 @@ def get_stash(m: re.Match[str]) -> str: value = stash.get(id) if value is not None: try: - return self.md.serializer(value) + # Ensure we don't have a placeholder inside a placeholder + return self.unescape(self.md.serializer(value)) except Exception: return r'\%s' % value diff --git a/tests/test_syntax/inline/test_raw_html.py b/tests/test_syntax/inline/test_raw_html.py index 57d725e7e..79d49a507 100644 --- a/tests/test_syntax/inline/test_raw_html.py +++ b/tests/test_syntax/inline/test_raw_html.py @@ -34,3 +34,9 @@ def test_inline_html_backslashes(self): def test_noname_tag(self): self.assertMarkdownRenders('', '

</>

') + + def test_markdown_nested_in_inline_comment(self): + self.assertMarkdownRenders( + 'Example: ', + '

Example:

' + ) From 7704724500b9fab461f834521526285365886af4 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Mon, 1 Dec 2025 09:50:07 -0500 Subject: [PATCH 2/3] changelog --- docs/changelog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 9c074b20b..d27a2f012 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,6 +10,12 @@ and this project adheres to the [Python Version Specification](https://packaging.python.org/en/latest/specifications/version-specifiers/). See the [Contributing Guide](contributing.md) for details. +## [unreleased] + +### Fixed + +* Ensure nested elements inside inline comments are properly unescaped (#1571). + ## [3.10.0] - 2025-11-03 ### Changed From 613406cb7cc576a131a54fd2ff3b4814bc547db1 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Mon, 1 Dec 2025 09:51:52 -0500 Subject: [PATCH 3/3] changelog --- docs/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index d27a2f012..25ff4047a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,7 +10,7 @@ and this project adheres to the [Python Version Specification](https://packaging.python.org/en/latest/specifications/version-specifiers/). See the [Contributing Guide](contributing.md) for details. -## [unreleased] +## [Unreleased] ### Fixed