Loose nested task lists could leave checkboxes outside <p> because
checkbox placement used list.loose before spacer detection finished.
Compute the final loose state first, then place checkboxes.
Fixes#4045
emStrong and del align maskedSrc with src by slicing the mask from the
end, so every mask must keep the length of the text it replaces. The
escape mask substituted a fixed two-character '++', but anyPunctuation is
/\\([\p{P}\p{S}])/gu and matches astral code points, so an escaped
character above U+FFFF is three code units masked as two.
The mask then ended up shorter than the source, the clip reached one code
unit too far back, and the resulting match.index was applied to src: the
closing delimiter was consumed a code unit late, leaving a stray
delimiter inside the emphasis and, for some inputs, dropping a character
of the document.
Substitute one '+' per code unit instead. '+' is punctuation, so the
delimiter flanking of the masked region is unchanged, and the ASCII case
still produces '++'.
Co-authored-by: Jayesh <jayesh.bhade@keychain.com>
A renderer extension named after a built-in token can return false to
fall back to the default renderer. The Parser decides that from a list
of built-in token type names, and 'checkbox' was never added to either
the block or the inline list when the checkbox token was introduced.
The result is that a `checkbox` renderer extension returning false
emits nothing instead of falling back, so the checkbox silently
disappears from the task item.
* fix: Avoid O(n^2) backtracking in HTML block close regex
The close branches end in `[^\n]*\n+`; the trailing `\n+` requires a
newline, so at EOF the close can't match and the engine retries every
split of the lazy `[\s\S]*?` before falling through to `$`, which is
O(n^2). `\n*` closes on first match and consumes identical text whenever
a trailing newline is present (the `[^\n]*` was added in #3991).
* fix: Avoid O(n^2) backtracking in tilde paragraph interrupt regex
The backtick branch is guarded by a lookahead but `~{3,}` isn't, and it
overlaps the following `[^\n]*`, so a long newline-less tilde run
backtracks quadratically. Since `~{3,}` is always followed by `[^\n]*`,
`~~~` matches the same strings without the overlap. The real fences
tokenizer is left untouched.
A blockquote followed by a bare list marker line (for example
`> foo\n-`) wrongly nested an empty list inside the blockquote.
The blockquote regex reuses the paragraph list-interrupt clause
` {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]`, whose trailing `[ \t]+[^ \t\n]`
requires content after the marker. A bare marker line therefore was
not seen as an interruption and got lazily continued into the
blockquote paragraph, then re-lexed into a nested empty list.
Give the blockquote its own paragraph variant whose list-interrupt
clause also matches a bare marker, so the list ends the blockquote and
becomes a sibling block. The top level paragraph rule is unchanged, so
an empty list still cannot interrupt a paragraph.
A line like `#1 Goals` or `#hashtag` followed by a setext underline was
rendered as a paragraph plus `<hr>` instead of a heading. A line only
starts an ATX heading when the `#`s are followed by whitespace or EOL, so
these are paragraph text and the underline makes a setext heading. The
lheading ATX-interrupt check was bare ` {0,3}#{1,6}`, missing the
`(?:\s|$)` that the paragraph and ATX heading rules already require.
A bare list marker followed only by a space (e.g. `- ` or `1. `) was not
recognized as a list and fell through to a paragraph, so `- ` rendered as
`<p>- </p>` instead of an empty list item. A marker with no trailing space
(`-`, `1.`) and an empty item that continues an existing list were already
handled correctly, making the behavior inconsistent.
The block `list` rule required content after the marker's whitespace
(`[ \t][^\n]+?`), so a marker followed only by whitespace failed to match.
Relax it to `[ \t][^\n]*?` so a marker with trailing whitespace and no
content still starts a list, matching the CommonMark reference and
markdown-it.
To keep CommonMark's rule that an empty list item cannot interrupt a
paragraph, the paragraph list-interrupt patterns now require a non-blank
character after the marker, so `foo\n+ ` stays a single paragraph while
`foo\n- bar` still interrupts.
* Cache list indentation regexes
* Handle zero indent in cached regexes
* Update src/rules.ts
Co-authored-by: Steven <steven@ceriously.com>
---------
Co-authored-by: Tony Brix <tony@brix.ninja>
Co-authored-by: Steven <steven@ceriously.com>
* fix(rules): ensure lookbehind regex is evaluated correctly by minifiers
* Use a default variable in the regex to prevent removal by minifiers
* fix(rules): remove unnecessary eslint directive for lookbehind regex
The title separator in the link regex used [ \t]* which allowed the
title group to be probed at every backtrack position of the greedy href
group. On long single-line input containing [text]( patterns without a
nearby closing ), this produced O(n²) per regex call and O(n³) in the
full inline tokenizer.
Change [ \t]* to [ \t]+|\n to require actual whitespace before the
title. This matches CommonMark spec requirements and eliminates the
backtracking cascade.
Before: 18K input takes ~36 seconds (event loop blocked)
After: 18K input takes ~45ms
BREAKING CHANGE:
- Change how consecutive text tokens work in lists
- Simplify listItem renderer
- Checkbox token is added in list tokenizer
- Checkbox token add type and raw property
- Change loose list text tokens to paragraph type in the list tokenizer
* fix: Avoid RegExp lookbehind assertions (#3816)
RegExp lookbehind assertions are supported in Safari >= 16.5, avoiding them
keeps support for older Safari versions.
* Improve perf of blockSkip on modern engines
RegExp lookbehind assertions are supported in Safari >= 16.5. But the
lookbehind-less version has a performance penalty. So having a fallback keeps
support for older Safari versions while maintaining performance for modern
engines.
* Add comment about lookbehind browser support
As suggested by @styfle
Co-authored-by: Steven <steven@ceriously.com>
---------
Co-authored-by: Steven <steven@ceriously.com>