Closed manuth closed 2 years ago
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 :)
Awesome, that would be great! Thanks a ton for taking care 😄
getTokensText
is released as part of v8.6.0!
Awesome! Thank you very much for your effort! 😄
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: https://github.com/valeriangalliat/markdown-it-anchor/blob/7f947ce9a0137ab68dbfef79a4c4d0a2ef4bfd37/index.js#L51This would allow users to make anchors look more like the ones generated by GitHub.
Thanks for your great work 😄