fix: let indented and type 3-5 html blocks interrupt a paragraph (#4124)

This commit is contained in:
kevin
2026-10-08 21:09:13 -06:00
committed by GitHub
parent 7e8754d60b
commit eaa1fffb30
3 changed files with 44 additions and 7 deletions
+7 -7
View File
@@ -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}}(?:</?(?:${_tag})(?: +|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--))`, 'i')),
htmlBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}(?:</?(?:${_tag})(?: +|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`, 'i')),
blockquoteBeginRegex: cachedIndentRegex((indent: number) => 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', '</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)')
.replace('tag', _tag) // pars can be interrupted by type (6) html blocks
.replace('html', ' {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)')
.replace('tag', _tag) // pars can be interrupted by html blocks of types (1) to (6)
.getRegex();
// only non-empty lists starting from 1 can interrupt paragraphs
@@ -230,8 +230,8 @@ const gfmTable = edit(
.replace('code', '(?: {4}| {0,3}\t)[^\\n]')
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)')
.replace('list', ' {0,3}(?:[*+-]|1[.)])[ \\t]') // any bullet ends the table rows
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)')
.replace('tag', _tag) // tables can be interrupted by type (6) html blocks
.replace('html', ' {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)')
.replace('tag', _tag) // tables can be interrupted by html blocks of types (1) to (6)
.getRegex();
const blockGfm: Record<BlockKeys, RegExp> = {
@@ -246,8 +246,8 @@ const blockGfm: Record<BlockKeys, RegExp> = {
.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', '</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)')
.replace('tag', _tag) // pars can be interrupted by type (6) html blocks
.replace('html', ' {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)')
.replace('tag', _tag) // pars can be interrupted by html blocks of types (1) to (6)
.getRegex(),
};
@@ -0,0 +1,17 @@
<p>Paragraph before an indented div</p>
<div>
*raw*
</div>
<p>Paragraph before an indented comment</p>
<!-- comment -->
<p>Paragraph before a processing instruction</p>
<?php echo 1; ?>
<p>Paragraph before a declaration</p>
<!DOCTYPE html>
<p>Paragraph before CDATA</p>
<![CDATA[ x ]]>
<blockquote>
<p>Paragraph in a blockquote</p>
<div>
</div>
</blockquote>
@@ -0,0 +1,20 @@
Paragraph before an indented div
<div>
*raw*
</div>
Paragraph before an indented comment
<!-- comment -->
Paragraph before a processing instruction
<?php echo 1; ?>
Paragraph before a declaration
<!DOCTYPE html>
Paragraph before CDATA
<![CDATA[ x ]]>
> Paragraph in a blockquote
> <div>
> </div>