add walkTokens and fix highlight async - #1664
Merged
Merged
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/markedjs/markedjs/1zxn2ys77 |
UziTech
commented
May 4, 2020
UziTech
commented
May 4, 2020
UziTech
commented
May 4, 2020
davisjam
reviewed
May 4, 2020
4 tasks
UziTech
marked this pull request as ready for review
May 13, 2020 01:02
styfle
reviewed
May 13, 2020
| marked.use(extension1); | ||
| marked.use(extension2); | ||
| marked('text'); | ||
| expect(walkedOnce).toBe(2); |
Member
There was a problem hiding this comment.
walkedOnce is 2? Maybe it should be renamed?
Member
Author
There was a problem hiding this comment.
That variable counts how many tokens were walked at least once
Contributor
There was a problem hiding this comment.
Perhaps nWalkedOnce and nWalkedTwice?
davisjam
approved these changes
May 14, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
tokensproperty 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
walkTokensoption 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.