Very long rendering time for `_a` and `*a`
Closed this issue · 3 comments
The following two snippets take about 11 seconds to be rendered to HTML on my machine:
First:
_a _a _a _a _a _a _a _a _a _a _a _a _a _a aaaaa
Second:
*a *a *a *a *a *a *a *a *a *a *a *a *a *a aaaaa
I think a similar issue was solved by defining StarLine
and UlLine
in markdown_parser.leg
.
Ouch, you're right. This is really a terrible problem, and StarLine
and UlLine
won't help here. The way I deal with this kind of issue in pandoc is by keeping track of nesting level in state. But I don't think we can do that in peg-markdown.
An even worse case, and harder to fix:
*a **a *a **a *a **a *a **a *a **a *a
**a *a **a aaaaa
Any ideas?
Well, the specs don't say anything about nesting asterisks / underlines. Thus, the parser may only have to change state once whenever it encounters *
, _
, **
, or __
and switch back when it encounters the same character group again.
I know that with lex one can define states and have rules match only when the lexer is in a certain state. Could we do the same here?
I think the idea I implement in this patch is simpler than what was there before, and it passes all my tests for nested emphasis.