From 1d7272f9ca02cdef3fb2ad061fa4da38b8978661 Mon Sep 17 00:00:00 2001 From: Wei-Lun Li Date: Tue, 3 Nov 2026 00:02:32 +0900 Subject: [PATCH] fix: keep a block quote open after a lazy line in a nested block quote (#4175) 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 --- src/Tokenizer.ts | 7 +++++ ...kquote_nested_lazy_outer_continuation.html | 30 +++++++++++++++++++ ...ockquote_nested_lazy_outer_continuation.md | 16 ++++++++++ 3 files changed, 53 insertions(+) create mode 100644 test/specs/new/blockquote_nested_lazy_outer_continuation.html create mode 100644 test/specs/new/blockquote_nested_lazy_outer_continuation.md diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index 3ee78c52..87090e17 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -285,6 +285,13 @@ export class _Tokenizer { raw = `${raw}\n${consumed.join('\n')}`; } text = text.substring(0, text.length - oldToken.text.length) + newToken.text; + + // A leftover line that starts with '>' still belongs to this + // blockquote; any other leftover line ends it. + lines = lines.slice(consumed.length); + if (lines.length > 0 && this.rules.other.blockquoteStart.test(lines[0])) { + continue; + } break; } else if (lastToken?.type === 'list') { // include continuation in nested list diff --git a/test/specs/new/blockquote_nested_lazy_outer_continuation.html b/test/specs/new/blockquote_nested_lazy_outer_continuation.html new file mode 100644 index 00000000..40a26c78 --- /dev/null +++ b/test/specs/new/blockquote_nested_lazy_outer_continuation.html @@ -0,0 +1,30 @@ +
+
+

a +b

+
+

c

+
+
+
+

a +b

+
+

heading

+
+
+
+

a +b

+
+
+
+
+
+

a +b

+
+
    +
  • item
  • +
+
diff --git a/test/specs/new/blockquote_nested_lazy_outer_continuation.md b/test/specs/new/blockquote_nested_lazy_outer_continuation.md new file mode 100644 index 00000000..7a19e8c1 --- /dev/null +++ b/test/specs/new/blockquote_nested_lazy_outer_continuation.md @@ -0,0 +1,16 @@ +> > a +b +> +> c + +> > a +b +> # heading + +> > a +b +> --- + +> > a +b +> - item