mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: keep lazy lines after a list in a nested blockquote (#4137)
This commit is contained in:
+11
-3
@@ -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
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user