Commit c0ddb80
committed
fix: escape a literal backslash in a text token
MarkdownRenderer.text() re-emitted a literal backslash bare, so a re-parse
consumed it as an escape for whatever followed. KaTeX's "\\(2^n\\)" came back
as "(2^n)", and a backslash ending a line turned into a hard line break.
Escape it first, ahead of the "*"/"_" and backtick escapes, the way
_escape_title() already does for the same reason. The escape is unconditional:
parse_escape gives each escaped character its own text token, so by then there
is no following character to condition on, and a lookahead rule misses the
reported case entirely.
The cost is a backslash that would not have been consumed being doubled too,
so a Windows path is re-emitted with doubled separators. One of the 652
bundled CommonMark examples changes this way. Over that corpus, meaning-
changing round-trips drop from 85 to 79 with none newly broken.
Reported by kbulygin on #480.1 parent 6e9b133 commit c0ddb80
2 files changed
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
49 | 61 | | |
50 | 62 | | |
51 | 63 | | |
| |||
0 commit comments