From 3fd93a460b41d90e874c80a79ff76949972a3468 Mon Sep 17 00:00:00 2001 From: cyphercodes Date: Tue, 23 Jun 2026 18:33:07 +0300 Subject: [PATCH] fix: keep ordered lists after blockquotes as siblings --- src/rules.ts | 11 ++++++++--- test/specs/new/ordered_list_after_blockquote.html | 12 ++++++++++++ test/specs/new/ordered_list_after_blockquote.md | 4 ++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 test/specs/new/ordered_list_after_blockquote.html create mode 100644 test/specs/new/ordered_list_after_blockquote.md diff --git a/src/rules.ts b/src/rules.ts index cc2e62bccf..3f8c02f05a 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -163,20 +163,25 @@ const html = edit( .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/) .getRegex(); -const paragraph = edit(_paragraph) +const createParagraph = (listInterrupt: RegExp) => edit(_paragraph) .replace('hr', hr) .replace('heading', ' {0,3}#{1,6}(?:\\s|$)') .replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs .replace('|table', '') .replace('blockquote', ' {0,3}>') .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n') - .replace('list', ' {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]') // only non-empty lists starting from 1 can interrupt + .replace('list', listInterrupt) .replace('html', ')|<(?:script|pre|style|textarea|!--)') .replace('tag', _tag) // pars can be interrupted by type (6) html blocks .getRegex(); +// only non-empty lists starting from 1 can interrupt paragraphs +const paragraph = createParagraph(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/); +// blockquotes can be interrupted by lists starting from any number +const blockquoteParagraph = createParagraph(/ {0,3}(?:[*+-]|\d{1,9}[.)])[ \t]+[^ \t\n]/); + const blockquote = edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/) - .replace('paragraph', paragraph) + .replace('paragraph', blockquoteParagraph) .getRegex(); /** diff --git a/test/specs/new/ordered_list_after_blockquote.html b/test/specs/new/ordered_list_after_blockquote.html new file mode 100644 index 0000000000..7ad76211be --- /dev/null +++ b/test/specs/new/ordered_list_after_blockquote.html @@ -0,0 +1,12 @@ +
    +
  1. test
  2. +
+
+

blockquote

+
+
    +
  1. test
  2. +
+
+

blockquote

+
diff --git a/test/specs/new/ordered_list_after_blockquote.md b/test/specs/new/ordered_list_after_blockquote.md new file mode 100644 index 0000000000..1ed45a9d6b --- /dev/null +++ b/test/specs/new/ordered_list_after_blockquote.md @@ -0,0 +1,4 @@ +1. test +> blockquote +2. test +> blockquote