Skip to content

Commit eaa1fff

Browse files
authored
fix: let indented and type 3-5 html blocks interrupt a paragraph (#4124)
1 parent 7e8754d commit eaa1fff

3 files changed

Lines changed: 44 additions & 7 deletions

File tree

‎src/rules.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const other = {
101101
headingBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}#`)),
102102
// a list item ends where a paragraph would be interrupted, so this mirrors the
103103
// html start conditions in the paragraph rule below; type 7 is excluded there
104-
htmlBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}(?:</?(?:${_tag})(?: +|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--))`, 'i')),
104+
htmlBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}(?:</?(?:${_tag})(?: +|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`, 'i')),
105105
blockquoteBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}>`)),
106106
};
107107

@@ -179,8 +179,8 @@ const createParagraph = (listInterrupt: RegExp) => edit(_paragraph)
179179
.replace('blockquote', ' {0,3}>')
180180
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)')
181181
.replace('list', listInterrupt)
182-
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)')
183-
.replace('tag', _tag) // pars can be interrupted by type (6) html blocks
182+
.replace('html', ' {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)')
183+
.replace('tag', _tag) // pars can be interrupted by html blocks of types (1) to (6)
184184
.getRegex();
185185

186186
// only non-empty lists starting from 1 can interrupt paragraphs
@@ -230,8 +230,8 @@ const gfmTable = edit(
230230
.replace('code', '(?: {4}| {0,3}\t)[^\\n]')
231231
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)')
232232
.replace('list', ' {0,3}(?:[*+-]|1[.)])[ \\t]') // any bullet ends the table rows
233-
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)')
234-
.replace('tag', _tag) // tables can be interrupted by type (6) html blocks
233+
.replace('html', ' {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)')
234+
.replace('tag', _tag) // tables can be interrupted by html blocks of types (1) to (6)
235235
.getRegex();
236236

237237
const blockGfm: Record<BlockKeys, RegExp> = {
@@ -246,8 +246,8 @@ const blockGfm: Record<BlockKeys, RegExp> = {
246246
.replace('blockquote', ' {0,3}>')
247247
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)')
248248
.replace('list', ' {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]') // only non-empty lists starting from 1 can interrupt
249-
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)')
250-
.replace('tag', _tag) // pars can be interrupted by type (6) html blocks
249+
.replace('html', ' {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)')
250+
.replace('tag', _tag) // pars can be interrupted by html blocks of types (1) to (6)
251251
.getRegex(),
252252
};
253253

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<p>Paragraph before an indented div</p>
2+
<div>
3+
*raw*
4+
</div>
5+
<p>Paragraph before an indented comment</p>
6+
<!-- comment -->
7+
<p>Paragraph before a processing instruction</p>
8+
<?php echo 1; ?>
9+
<p>Paragraph before a declaration</p>
10+
<!DOCTYPE html>
11+
<p>Paragraph before CDATA</p>
12+
<![CDATA[ x ]]>
13+
<blockquote>
14+
<p>Paragraph in a blockquote</p>
15+
<div>
16+
</div>
17+
</blockquote>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Paragraph before an indented div
2+
<div>
3+
*raw*
4+
</div>
5+
6+
Paragraph before an indented comment
7+
<!-- comment -->
8+
9+
Paragraph before a processing instruction
10+
<?php echo 1; ?>
11+
12+
Paragraph before a declaration
13+
<!DOCTYPE html>
14+
15+
Paragraph before CDATA
16+
<![CDATA[ x ]]>
17+
18+
> Paragraph in a blockquote
19+
> <div>
20+
> </div>

0 commit comments

Comments
 (0)