-
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
add walkTokens and fix highlight async #1664
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/markedjs/markedjs/1zxn2ys77 |
marked.use(extension1); | ||
marked.use(extension2); | ||
marked('text'); | ||
expect(walkedOnce).toBe(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
walkedOnce is 2? Maybe it should be renamed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That variable counts how many tokens were walked at least once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps nWalkedOnce
and nWalkedTwice
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Marked version: 1.0.0
Description
Using an async highlighting function was broken in v1.0.0 when we moved block tokens in blockquote and lists from the top level of the tokens array to a
tokens
property on the blockquote or listitem token.This PR adds a public method to easily iterate over all tokens and send each token to a function specified by the user (
marked.walkTokens(tokens, callback)
) and uses that function to highlight code blocks asynchronously.This also adds a
walkTokens
option so extensions can use it to run a function for each token.Example: Overriding heading tokens to start at h2.
Output:
Contributor
Committer
In most cases, this should be a different person than the contributor.