-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Support highlighting codespan using highlight option + or support async function in Renderer #1780
Comments
duplicate of #458 PRs are welcome 😁 |
Well, this had two sections. The first one can be simpler I think since the highlight function already exists for |
The issue with highlighting codespans is that you can't tell marked what language it is because there can't be an infostring like a code block. You could always do the highlighting after running the markdown through marked. |
I can by using a lambda. For example, here I don't care about "lang" at all. I just supply my own "scopeName" (language) |
You could use a walkTokens function: const walkTokens = (token) => {
if (token.type === 'codespan') {
token.text = highlight(token.text);
}
};
marked.use({ walkTokens }); For an async walk tokens function you will have to await all of the promises. const tokens = marked.lexer(md, opts);
const promises = [];
marked.walkTokens(tokens, (token) => {
if (token.type === 'codespan') {
promises.push(asyncFunction(token));
}
});
await Promise.all(promises);
const html = marked.parser(tokens, opts); |
Describe the feature
Currently, marked only allows specifying a highlight function for code blocks and not inline code (codespan).
Using the custom Renderer is not possible because
(new Renderer()).codespan
does not accept async functions. Thus, there is no way to use an async highlighter for highlighting codespan unless an exoteric solution like deasync is used.Why is this feature necessary?
To highlight inline code.
Describe alternatives you've considered
Using a Pandoc renderer. However,
lang
can be provided externally through other parts of the code, and so this is independent of supporting Pandoc syntax for giving the language through the markdown syntax.The text was updated successfully, but these errors were encountered: