From 0112ce84a7830d772ccce640ed62200a90d08620 Mon Sep 17 00:00:00 2001 From: Osama Ansar Date: Mon, 12 Oct 2026 22:02:01 +0500 Subject: [PATCH] fix: do not continue a block quote paragraph from a whitespace-only line In `> a\n> \nb` the marker consumes one space and the remaining whitespace-only text matched the lazy paragraph branch of the blockquote rule, which then swallowed the following unquoted line into the quote. A line with only whitespace after the marker is blank and must end the paragraph, as for `>` and `> `. --- src/rules.ts | 4 +++- test/specs/new/blockquote_whitespace_only_empty.html | 3 +++ test/specs/new/blockquote_whitespace_only_empty.md | 2 ++ test/specs/new/blockquote_whitespace_only_line.html | 8 ++++++++ test/specs/new/blockquote_whitespace_only_line.md | 7 +++++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/specs/new/blockquote_whitespace_only_empty.html create mode 100644 test/specs/new/blockquote_whitespace_only_empty.md create mode 100644 test/specs/new/blockquote_whitespace_only_line.html create mode 100644 test/specs/new/blockquote_whitespace_only_line.md diff --git a/src/rules.ts b/src/rules.ts index 02e12330c8..2693902d16 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -190,7 +190,9 @@ const paragraph = createParagraph(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/); // paragraph, where an empty list cannot interrupt) const blockquoteParagraph = createParagraph(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/); -const blockquote = edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/) +// a line with only whitespace after the marker is blank, so it must not start a +// paragraph that lazily continues onto the next line +const blockquote = edit(/^( {0,3}> ?(?:(?![ \t]*(?:\n|$))(paragraph)|[^\n]*)(?:\n|$))+/) .replace('paragraph', blockquoteParagraph) .getRegex(); diff --git a/test/specs/new/blockquote_whitespace_only_empty.html b/test/specs/new/blockquote_whitespace_only_empty.html new file mode 100644 index 0000000000..c630a798d4 --- /dev/null +++ b/test/specs/new/blockquote_whitespace_only_empty.html @@ -0,0 +1,3 @@ +
+
+

b

diff --git a/test/specs/new/blockquote_whitespace_only_empty.md b/test/specs/new/blockquote_whitespace_only_empty.md new file mode 100644 index 0000000000..c5d1e53afb --- /dev/null +++ b/test/specs/new/blockquote_whitespace_only_empty.md @@ -0,0 +1,2 @@ +> +b diff --git a/test/specs/new/blockquote_whitespace_only_line.html b/test/specs/new/blockquote_whitespace_only_line.html new file mode 100644 index 0000000000..c88b315b86 --- /dev/null +++ b/test/specs/new/blockquote_whitespace_only_line.html @@ -0,0 +1,8 @@ +
+

a

+
+

b

+
+

c

+
+

d

diff --git a/test/specs/new/blockquote_whitespace_only_line.md b/test/specs/new/blockquote_whitespace_only_line.md new file mode 100644 index 0000000000..fa3a72cb4c --- /dev/null +++ b/test/specs/new/blockquote_whitespace_only_line.md @@ -0,0 +1,7 @@ +> a +> +b + +> c +> +d