marked
marked copied to clipboard
Rules on lexers should be deep copied
If I change a rule on one lexer, that change ends up getting applied to other lexers as observed with the following:
> var lexer = new marked.Lexer();
undefined
> lexer.rules.heading
/^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
> var newLexer = new marked.Lexer();
undefined
> newLexer.rules.heading
/^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
> lexer.rules.heading = /^ *(#{1,6} ) +([^\n]+?) *#* *(?:\n+|$)/
/^ *(#{1,6} ) +([^\n]+?) *#* *(?:\n+|$)/
> lexer.rules.heading
/^ *(#{1,6} ) +([^\n]+?) *#* *(?:\n+|$)/
> newLexer.rules.heading
/^ *(#{1,6} ) +([^\n]+?) *#* *(?:\n+|$)/
The change should have only been applied to lexer and not newLexer. This happens because the rules are not deep copied when a new lexer is constructed.
Got exactly the same problem.
You've got a point. @joshbruce I'd flag this for developer experience
@Feder1co5oave: Thinking labels for lexer, parser (already have), and whatever else might be beneficial as well. Thoughts??
I honestly don't think those kind of categories would help
Fair enough. Let's see how it goes then. :)
Rules is not strictly a public API, so I feel like this is not a valid way to extend marked. Now we have custom extensions that should be used instead.