diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index ac9c7469..22547148 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -285,9 +285,17 @@ export class _Tokenizer { 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; } } diff --git a/test/specs/new/blockquote_nested_list_lazy_lines.html b/test/specs/new/blockquote_nested_list_lazy_lines.html new file mode 100644 index 00000000..e4163d35 --- /dev/null +++ b/test/specs/new/blockquote_nested_list_lazy_lines.html @@ -0,0 +1,19 @@ +
+
+
    +
  • a +b +c
  • +
+
+
+
+
+
    +
  • a
  • +
  • b +c +d
  • +
+
+
diff --git a/test/specs/new/blockquote_nested_list_lazy_lines.md b/test/specs/new/blockquote_nested_list_lazy_lines.md new file mode 100644 index 00000000..06d388ab --- /dev/null +++ b/test/specs/new/blockquote_nested_list_lazy_lines.md @@ -0,0 +1,8 @@ +> > - a +> b +c + +> > - a +> > - b +> c +d diff --git a/test/unit/Lexer.test.js b/test/unit/Lexer.test.js index 3661921c..eab72cc2 100644 --- a/test/unit/Lexer.test.js +++ b/test/unit/Lexer.test.js @@ -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', () => {