Skip to content

Commit

Permalink
Give smarty tree processor higher priority than toc
Browse files Browse the repository at this point in the history
And add a test for using smarty in ToC headers.

Fixes #1438.
  • Loading branch information
mitya57 authored Feb 5, 2024
1 parent c334a3e commit 421f1e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion markdown/extensions/smarty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(['"', "'"])


Expand Down
23 changes: 23 additions & 0 deletions tests/test_syntax/extensions/test_smarty.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,26 @@ def test_custom_substitutions(self):
'Must not be confused with &sbquo;ndash&lsquo; (\u2013) \u2026 ]</p>'
)
self.assertMarkdownRenders(text, html)


class TestSmartyAndToc(TestCase):

default_kwargs = {
'extensions': ['smarty', 'toc'],
}

def test_smarty_and_toc(self):
self.assertMarkdownRenders(
'# *Foo* --- `bar`',
'<h1 id="foo-bar"><em>Foo</em> &mdash; <code>bar</code></h1>',
expected_attrs={
'toc_tokens': [
{
'level': 1,
'id': 'foo-bar',
'name': 'Foo &mdash; bar',
'children': [],
},
],
},
)

0 comments on commit 421f1e8

Please sign in to comment.