diff --git a/docs/changelog.md b/docs/changelog.md index 9c074b20b..25ff4047a 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 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:
' + )