Skip to content

walkTokens and local context #3093

Answered by UziTech
j3rem1e asked this question in Q&A
Nov 14, 2023 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Is it costly to create a Marked instance?

I don't think we have any metrics on how costly it is to create a marked instance but it shouldn't be too costly.

If it's costly, how to optimize the creation of instances?

If each instance uses the same extensions you should be able to reuse the instance and just run marked.parse again.

Can I implement a walkTokens using a context without creating a new Marked instance?

Yes. WalkTokens does not have context of parent tokens, but you can create your own version of walk tokens that does.

Something like:

const tokens = marked.lexer(markdown);

// update tokens here

const html = marked.parser(tokens);

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by j3rem1e
Comment options

You must be logged in to vote
1 reply
@UziTech
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants