Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The title from toc_tokens ignores the smarty extension #1438

Closed
oprypin opened this issue Feb 3, 2024 · 3 comments · Fixed by #1440
Closed

The title from toc_tokens ignores the smarty extension #1438

oprypin opened this issue Feb 3, 2024 · 3 comments · Fixed by #1440
Labels
confirmed Confirmed bug report or approved feature request. extension Related to one or more of the included extensions. needs-decision A decision needs to be made regarding request.

Comments

@oprypin
Copy link
Contributor

oprypin commented Feb 3, 2024

Current actual result:

>>> import markdown
>>> md = markdown.Markdown(extensions=['toc', 'smarty'])
>>> md.convert('# *Foo* --- `bar`')
'<h1 id="foo-bar"><em>Foo</em> &mdash; <code>bar</code></h1>'
>>> md.toc_tokens
[{'level': 1, 'id': 'foo-bar', 'name': 'Foo --- bar', 'children': []}]

Expected result:

[{'level': 1, 'id': 'foo-bar', 'name': 'Foo &mdash; bar', 'children': []}]

Background where I discovered this: mkdocs/mkdocs#3357 (comment)

This happens because smarty runs at a lower priority than toc (unlike most other treeprocessors) and it doesn't have a chance to kick in.

This other extension is presumably affected in the same way, probably among others:
https://github.com/facelessuser/pymdown-extensions/blob/8f5283f71e8833f1ba0fa0bbe2680e1ad2c6cb19/pymdownx/smartsymbols.py#L167

Something should be done so that all the rest of the treeprocessors are also applied before saving the title. Maybe postprocessors too, rather than applying the unescape functionality out-of-band.

@oprypin
Copy link
Contributor Author

oprypin commented Feb 3, 2024

By the way, please don't solve this by lowering the priority of the toc extension, so much stuff I made already depends on its precise priority 🥲

@waylan
Copy link
Member

waylan commented Feb 4, 2024

I didn't have much involvement in the smarty extension, which was added much later than TOC. I wonder why it was given a lower priority. @mitya57 do you recall? I seem to recall you being involved in the development of the smarty extension.

I ask why because, barring any good reason not to, I have no object in raising the priority to be before TOC.

@waylan waylan added extension Related to one or more of the included extensions. needs-decision A decision needs to be made regarding request. confirmed Confirmed bug report or approved feature request. labels Feb 4, 2024
mitya57 added a commit to mitya57/markdown that referenced this issue Feb 5, 2024
And add a test for using smarty in ToC headers.

Fixes Python-Markdown#1438.
@mitya57
Copy link
Collaborator

mitya57 commented Feb 5, 2024

When I added smarty treeprocessor in 47ec0cb, I probably just pushed it to the end without thinking too much.

The tests pass when changing its priority, so I think it's fine to do that. Submitted PR as #1440.

mitya57 added a commit to mitya57/markdown that referenced this issue Feb 5, 2024
And add a test for using smarty in ToC headers.

Fixes Python-Markdown#1438.
waylan pushed a commit that referenced this issue Feb 5, 2024
And add a test for using smarty in ToC headers.

Fixes #1438.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed Confirmed bug report or approved feature request. extension Related to one or more of the included extensions. needs-decision A decision needs to be made regarding request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants