fix: keep lazy lines after a list in a nested blockquote (#4137)

This commit is contained in:
Wahid Rizka Fathurrohman
2026-10-25 23:36:02 -06:00
committed by GitHub
parent e7c4f64c43
commit 38c7e55207
4 changed files with 88 additions and 3 deletions
+11 -3
View File
@@ -285,9 +285,17 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
const newToken = this.list(newText)!;
tokens[tokens.length - 1] = newToken;
raw = raw.substring(0, raw.length - lastToken.raw.length) + newToken.raw;
text = text.substring(0, text.length - oldToken.raw.length) + newToken.raw;
lines = newText.substring(tokens.at(-1)!.raw.length).split('\n');
// The list raw has no '>' markers, so it cannot be cut out of `raw`.
// Count the continuation lines the list took and add those lines instead.
const consumedCount = newToken.raw.length > oldToken.raw.length
? newText.slice(oldToken.raw.length + 1, newToken.raw.length).split('\n').length
: 0;
if (consumedCount > 0) {
const consumed = lines.slice(0, consumedCount).join('\n');
raw = `${raw}\n${consumed}`;
text = `${text}\n${consumed}`;
}
lines = lines.slice(consumedCount);
continue;
}
}
@@ -0,0 +1,19 @@
<blockquote>
<blockquote>
<ul>
<li>a
b
c</li>
</ul>
</blockquote>
</blockquote>
<blockquote>
<blockquote>
<ul>
<li>a</li>
<li>b
c
d</li>
</ul>
</blockquote>
</blockquote>
@@ -0,0 +1,8 @@
> > - a
> b
c
> > - a
> > - b
> c
d
+50
View File
@@ -638,6 +638,56 @@ a | b
],
});
});
it('lazy line in a nested list', () => {
expectTokens({
md: '> - a\n> - b\nc',
tokens: [
{
type: 'blockquote',
raw: '> - a\n> - b\nc',
tokens: [
{
type: 'list',
raw: '- a\n- b\nc',
ordered: false,
start: '',
loose: false,
items: [
{
type: 'list_item',
raw: '- a\n',
task: false,
loose: false,
text: 'a',
tokens: [{
type: 'text',
raw: 'a',
text: 'a',
tokens: [{ type: 'text', raw: 'a', text: 'a', escaped: false }],
}],
},
{
type: 'list_item',
raw: '- b\nc',
task: false,
loose: false,
text: 'b\nc',
tokens: [{
type: 'text',
raw: 'b\nc',
text: 'b\nc',
tokens: [{ type: 'text', raw: 'b\nc', text: 'b\nc', escaped: false }],
}],
},
],
},
],
text: '- a\n- b\nc',
},
],
});
});
});
describe('list', () => {