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

KaTeX Expressions aren't Included in Headings #112

Closed
manuth opened this issue Apr 6, 2022 · 4 comments · Fixed by #113
Closed

KaTeX Expressions aren't Included in Headings #112

manuth opened this issue Apr 6, 2022 · 4 comments · Fixed by #113

Comments

@manuth
Copy link
Contributor

manuth commented Apr 6, 2022

Currently, KaTeX expressions inside of headings aren't part of the anchors.
I'd love to either have an option for configuring additional token-types to include in anchors or to have the token type math_inline added to this filter:

.filter(token => token.type === 'text' || token.type === 'code_inline')

This would allow users to make anchors look more like the ones generated by GitHub.

Thanks for your great work 😄

@valeriangalliat
Copy link
Owner

valeriangalliat commented Apr 8, 2022

Interesting! I'm thinking I could use a blacklist approach instead of the current whitelist approach, e.g. doing .filter(token => token.type !== 'html_inline' && token.type !== 'image') instead of .filter(token => token.type === 'text' || token.type === 'code_inline').

This yields the same output with all my tests using native markdown-it tokens but in the case of the KaTeX plugin, that would include the expression as well. This would be a breaking change though and that behavior might be undesirable with other plugins, so I guess it's safer to leave it as is and introduce a configuration option...

Probably something like:

md.use(anchor, {
  getTokensText: tokens => tokens.filter(t => t.type !== 'html_inline' && t.type !== 'image').map(t => t.content).join('')
})

I'll give it some more thoughts and get back to you :)

@manuth
Copy link
Contributor Author

manuth commented Apr 8, 2022

Awesome, that would be great!
Thanks a ton for taking care 😄

@valeriangalliat
Copy link
Owner

valeriangalliat commented Apr 8, 2022

getTokensText is released as part of v8.6.0!

@manuth
Copy link
Contributor Author

manuth commented Apr 11, 2022

Awesome! Thank you very much for your effort! 😄

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

Successfully merging a pull request may close this issue.

2 participants