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

Advice for keeping permalink symbol token stable #98

Closed
meteorlxy opened this issue Jul 1, 2021 · 5 comments
Closed

Advice for keeping permalink symbol token stable #98

meteorlxy opened this issue Jul 1, 2021 · 5 comments

Comments

@meteorlxy
Copy link
Contributor

meteorlxy commented Jul 1, 2021

We were using html_block token for permalink symbol in v7.x:

Object.assign(new state.Token('html_block', '', 0), { content: opts.permalinkSymbol }),

Since v8.x, it's changed to html_inline (which is not the "exact" legacy implementation):

Object.assign(new state.Token('html_inline', '', 0), { content: opts.permalinkSymbol }),

It's an internal / undocumented breaking change, which might break some plugins that depend on markdown-it-anchor.

For example, we have a custom toc plugin, allowing html_inline in the heading to be displayed in the toc headers. Now we need one more step to filter the symbol token.

This issue is just a reminder in case next time you may change it unintentionally.

You can close it after reading 😄 @valeriangalliat


BTW, do you have any advices for how to filter the permalink symbol token, and keep other html_inline tokens?

@valeriangalliat
Copy link
Owner

Ouuh, good catch, the legacy version should be identical in all points, I'll publish a patch for this

As for your question, I think that including the toc plugin before markdown-it-anchor would solve the problem, since the toc would be generated before the anchors are added to the token stream?

@valeriangalliat
Copy link
Owner

The legacy permalink is compliant with the actual legacy implementation in 8.0.5!

@meteorlxy
Copy link
Contributor Author

As for your question, I think that including the toc plugin before markdown-it-anchor would solve the problem, since the toc would be generated before the anchors are added to the token stream?

We are using the slug generated by markdown-it-anchor (i.e. id attr of the heading_open token) as the href link of the toc, so it's better to generate toc after anchor.

@meteorlxy
Copy link
Contributor Author

meteorlxy commented Jul 1, 2021

@valeriangalliat Is it possible to add a meta.isPermalinkSymbol (or similar) to the symbol token? 🤔

@valeriangalliat
Copy link
Owner

Ah I see, makes sense. meta.isPermalinkSymbol seems like a great idea indeed! I've made a PR for this, #99, feel free to test against it (npm i valeriangalliat/markdown-it-anchor#feature/permalink-symbol-meta) and let me know if that solves your problem :)

valeriangalliat added a commit that referenced this issue Jul 1, 2021
…meta

Support permalink symbol token meta (#98)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants