From eaa1fffb30fa334cc11ab93f1e5aaa1d2b916e7c Mon Sep 17 00:00:00 2001 From: kevin <5299031+kevin9327@users.noreply.github.com> Date: Fri, 9 Oct 2026 12:09:13 +0900 Subject: [PATCH] fix: let indented and type 3-5 html blocks interrupt a paragraph (#4124) --- src/rules.ts | 14 ++++++------- .../new/html_block_interrupts_paragraph.html | 17 ++++++++++++++++ .../new/html_block_interrupts_paragraph.md | 20 +++++++++++++++++++ 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 test/specs/new/html_block_interrupts_paragraph.html create mode 100644 test/specs/new/html_block_interrupts_paragraph.md diff --git a/src/rules.ts b/src/rules.ts index 81da76a9..6e9c4126 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -101,7 +101,7 @@ export const other = { headingBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}#`)), // a list item ends where a paragraph would be interrupted, so this mirrors the // html start conditions in the paragraph rule below; type 7 is excluded there - htmlBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}(?:)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--))`, 'i')), + htmlBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}(?:)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?| new RegExp(`^ {0,${indent}}>`)), }; @@ -179,8 +179,8 @@ const createParagraph = (listInterrupt: RegExp) => edit(_paragraph) .replace('blockquote', ' {0,3}>') .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)') .replace('list', listInterrupt) - .replace('html', ')|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)') - .replace('tag', _tag) // pars can be interrupted by type (6) html blocks + .replace('html', ' {0,3}(?:)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)') - .replace('tag', _tag) // tables can be interrupted by type (6) html blocks + .replace('html', ' {0,3}(?:)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?| = { @@ -246,8 +246,8 @@ const blockGfm: Record = { .replace('blockquote', ' {0,3}>') .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)') .replace('list', ' {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]') // only non-empty lists starting from 1 can interrupt - .replace('html', ')|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)') - .replace('tag', _tag) // pars can be interrupted by type (6) html blocks + .replace('html', ' {0,3}(?:)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|Paragraph before an indented div

+
+*raw* +
+

Paragraph before an indented comment

+ +

Paragraph before a processing instruction

+ +

Paragraph before a declaration

+ +

Paragraph before CDATA

+ +
+

Paragraph in a blockquote

+
+
+
diff --git a/test/specs/new/html_block_interrupts_paragraph.md b/test/specs/new/html_block_interrupts_paragraph.md new file mode 100644 index 00000000..5eb3c9d1 --- /dev/null +++ b/test/specs/new/html_block_interrupts_paragraph.md @@ -0,0 +1,20 @@ +Paragraph before an indented div +
+*raw* +
+ +Paragraph before an indented comment + + +Paragraph before a processing instruction + + +Paragraph before a declaration + + +Paragraph before CDATA + + +> Paragraph in a blockquote +>
+>