-
Hello, I have implemented a plugin to transform some elements in the markdown using a "local context": Each markdown is parsed to html using a context linked to the markdown. For example, it transforms links or code blocks using properties of the parent component to contextualize some graphics or href. In order to do that, I have to create a new Marked instance every time I want to parse the markdown. My question is mainly about performances:
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
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 each instance uses the same extensions you should be able to reuse the instance and just run
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); |
Beta Was this translation helpful? Give feedback.
-
If I call myself lexer/walk/parser, I have to reimplements some logics already handled by marked, like calling hooks, walkTokens of possible extensions, etc, no ? |
Beta Was this translation helpful? Give feedback.
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 each instance uses the same extensions you should be able to reuse the instance and just run
marked.parse
again.Yes. WalkTokens does not have context of parent tokens, but you can create your own version of walk tokens that does.
Something like: