From 421f1e88ff4661b4433b97ec57b040a2a74e5aed Mon Sep 17 00:00:00 2001
From: Dmitry Shachnev
Date: Mon, 5 Feb 2024 16:43:49 +0300
Subject: [PATCH] Give smarty tree processor higher priority than toc
And add a test for using smarty in ToC headers.
Fixes #1438.
---
docs/changelog.md | 1 +
markdown/extensions/smarty.py | 2 +-
tests/test_syntax/extensions/test_smarty.py | 23 +++++++++++++++++++++
3 files changed, 25 insertions(+), 1 deletion(-)
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`',
+ 'Foo — bar
',
+ expected_attrs={
+ 'toc_tokens': [
+ {
+ 'level': 1,
+ 'id': 'foo-bar',
+ 'name': 'Foo — bar',
+ 'children': [],
+ },
+ ],
+ },
+ )