* fix: measure tabs after a block quote marker from the start of the line
- Expand tabs in block quote markers and the indentation after them with tab stops from the start of the line, nested markers included
- Keep tabs literal inside fenced code in a block quote (#4184)
- Keep the old handling inside list items, where the marker's column is unknown
Fixes#4221
* fix: keep the existing tab handling from a list item in a block quote on
- Return lines as written from the first list item on, since its columns and fences are not tracked
- Expand columns only in the outermost block quote, including the nested continuation path
- Add exact and structural specs for a fence and a lazy line in a list item under a block quote
* fix: keep an indented code block after a list item paragraph
In a list item, a paragraph line indented four or more spaces is lexed
as indented code and then merged back into the paragraph. The code
token also ran across the following blank line, so a real indented
code block after it was merged into the paragraph too.
* fix: continue list item text over indented lines in the text tokenizer
* fix: keep tabs that are code content under a block quote
After ">", an optional space is part of the marker; tabs after that
space belong to the line content (e.g. fenced code) and must not be
expanded. Tabs with no leading space are still expanded so indented
code under a quote keeps working.
Fixes#4184
* test: move the block quote tab case to a renderExact spec
* perf: skip dead emphasis/strikethrough delim runs in inline pass
Follow-up to #4099 / #4103. When an input line contains a long run of `*`,
`_` or `~` with no closer anywhere ahead in maskedSrc, every opener
position in Tokenizer.emStrong / Tokenizer.del was correctly early-returning
via the lastPossibleCloserIndex guard introduced by #4103, but the outer
inline loop still advanced one character at a time through the run. The
`^\*+` greedy anchor in emStrongLDelim re-scans the whole run on each
call, so the inline pass remains O(n^2) even though the inner closer scan
is now O(1).
Measured on master before this change:
```
**` x 20000 + 'x' 8.73 s
__` x 20000 + 'x' 11.30 s
*` x 40000 + 'x' 8.73 s
_` x 40000 + 'x' 11.30 s
```
With this change the same inputs render in ~0.001 s. The CommonMark
spec test suite (1983 cases) and the project's unit tests (242 cases)
continue to pass. A new fixture `em_strong_unmatched_delim_run`
documents the behavior for closer-less `*`, `_`, and `~` runs.
The fix checks the cached last-possible-closer index that #4103
already maintains; when no closer exists after the current position,
the entire run of same-delim characters is consumed as literal text in
one step. Behavior is unchanged (runs without a closer have always
rendered as literal text); only the time to reach that result changes.
* test(redos): regression test for closer-less delimiter run quadratic
Mirrors the quadratic_em_mask.cjs / quadratic_br.cjs style. Each of the
four cases fails on 18.1.3 baseline (times out around 2.3-3.0s per case
in test:specs) and passes in 5-7ms with the fix.
- '**' x 10000 + 'x' -> <p>**...**x</p>
- '__' x 10000 + 'x' -> <p>__...__x</p>
- '*' x 20000 + 'x' -> <p>*...*x</p>
- '_' x 20000 + 'x' -> <p>_..._x</p>
Requested by @UziTech in review of #4196.
* Fix bracket escapes inside code spans in link text being stripped
The link label matcher consumes backslash-escaped brackets, and outputLink then removes those escapes from the label text. It did so over the whole label, so a backslash-escaped bracket inside a code span also lost its backslash even though code span content is literal: [`\]`] rendered <code>]</code> instead of <code>\]</code>.
Scan the label and copy code spans through verbatim, unescaping brackets only outside of them.
Refs #4176
Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
* Add spec tests for bracket escapes in link text code spans
Refs #4176
Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
* Add expected HTML for bracket escapes in link text code spans
Refs #4176
Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
---------
Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
* fix: continue a block quote paragraph with a lazy line that starts an html tag
A lazy continuation line in a block quote that is only an html tag, like
`</span>` or `<a href="bar">`, was lexed as an html block, which ended the
paragraph. An html block of type 7 cannot interrupt a paragraph, so the
line continues the paragraph, as in CommonMark.
* refactor: move the lazy html paragraph check to the tokenizer
* fix: only let a non-empty list starting with 1 interrupt a paragraph in a list item
Inside a list item, paragraph lines are lexed as text tokens, and the list
tokenizer ran before the text tokenizer without checking whether the list
may interrupt the paragraph, so `14.` or an empty `*` on the next line
started a nested list. Apply the same rule as the paragraph interrupt: only
a non-empty list starting with a bullet or 1 can interrupt a paragraph.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor: move the list interrupt check into the list tokenizer
The lexer passes its tokens to `list(src, tokens)`, and the tokenizer
checks the last one, so `list(src)` overrides keep working.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor: keep the block tokens in the lexer state for the list tokenizer
`blockTokens` sets `this.lexer.state.tokens` to the tokens it is lexing
and restores the outer ones when it returns, so `list(src)` keeps its
signature and checks the token before it from the state.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor: keep only the last block token in the lexer state
`blockTokens` records the last token of the run it is lexing in
`this.lexer.state.lastToken` before each tokenizer runs, and restores the
outer one when a nested call returns, so the list tokenizer checks
`state.lastToken` instead of the whole token list.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
fix: end a list item before a lazy line after a nested block
A line with less indentation than a list item is only a lazy
continuation when it continues a paragraph. The list tokenizer checked
the previous line for a fence, heading or hr, but it used the regexes
scaled to the item indent on a line that is already relative to the
item content, and it did not look inside a nested list item or
blockquote on that line. So text after `- - # heading`, `- > ***`, or a
fenced code block in a nested item was pulled into the outer item.
After a lazy continuation line in a nested block quote, a following line
that starts with ">" but does not continue the inner paragraph (a blank
">", a heading, a thematic break, a list item, ...) started a new
top-level block quote. It belongs to the outer block quote, as in
CommonMark.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>