diff --git a/docs/changelog.md b/docs/changelog.md index 884320f7..33f05ce8 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Include `scripts/*.py` in the generated source tarballs (#1430). * Ensure lines after heading in loose list are properly detabbed (#1443). +* Give smarty tree processor higher priority than toc (#1440). ## [3.5.2] -- 2024-01-10 diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py index 0ce7772a..7a7c952d 100644 --- a/markdown/extensions/smarty.py +++ b/markdown/extensions/smarty.py @@ -269,7 +269,7 @@ def extendMarkdown(self, md): self.educateDashes(md) inlineProcessor = InlineProcessor(md) inlineProcessor.inlinePatterns = self.inlinePatterns - md.treeprocessors.register(inlineProcessor, 'smarty', 2) + md.treeprocessors.register(inlineProcessor, 'smarty', 6) md.ESCAPED_CHARS.extend(['"', "'"]) diff --git a/tests/test_syntax/extensions/test_smarty.py b/tests/test_syntax/extensions/test_smarty.py index aeb09884..8a176745 100644 --- a/tests/test_syntax/extensions/test_smarty.py +++ b/tests/test_syntax/extensions/test_smarty.py @@ -198,3 +198,26 @@ def test_custom_substitutions(self): 'Must not be confused with ‚ndash‘ (\u2013) \u2026 ]

' ) self.assertMarkdownRenders(text, html) + + +class TestSmartyAndToc(TestCase): + + default_kwargs = { + 'extensions': ['smarty', 'toc'], + } + + def test_smarty_and_toc(self): + self.assertMarkdownRenders( + '# *Foo* --- `bar`', + '

Foobar

', + expected_attrs={ + 'toc_tokens': [ + { + 'level': 1, + 'id': 'foo-bar', + 'name': 'Foo — bar', + 'children': [], + }, + ], + }, + )