Skip to content
Open
24 changes: 12 additions & 12 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,27 +144,27 @@ const _htmlInterrupt = edit(' {0,3}(?:</?(?:tag)(?:[ \\t]+|\\n|/?>)|<(?:(?:scrip
// The underline may end with spaces or tabs (CommonMark §4.3). Internal
// spaces or tabs still fail to match, and more than three spaces of indent
// still do not.
const lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+)[ \t]*(?:\n+|$)/;
const lheading = edit(lheadingCore)
.replace(/bull/g, bullet) // lists can interrupt
const lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|listInterrupt|fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+)[ \t]*(?:\n+|$)/;
const createLheading = (listInterrupt: RegExp) => edit(lheadingCore)
.replace('listInterrupt', listInterrupt)
.replace(/bull/g, bullet) // a list can start a block with any number
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code can start a block but cannot interrupt a paragraph
.replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
.replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
.replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/) // ATX heading can interrupt
.replace(/hr/g, / {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/) // thematic break can interrupt
.replace(/hr/g, / {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/); // thematic break can interrupt
const lheading = createLheading(other.listInterruptsParagraph)
.replace(/\|table/g, '') // table not in commonmark
.replace(/html/g, _htmlInterrupt) // block html of types (1) to (6) can interrupt
.getRegex();
const lheadingGfm = edit(lheadingCore)
.replace(/bull/g, bullet) // lists can interrupt
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code can start a block but cannot interrupt a paragraph
.replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
.replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
.replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/) // ATX heading can interrupt
.replace(/hr/g, / {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/) // thematic break can interrupt
const lheadingGfm = createLheading(other.listInterruptsParagraph)
.replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/) // table can interrupt
.replace(/html/g, _htmlInterrupt) // block html of types (1) to (6) can interrupt
.getRegex();
const lheadingPedantic = createLheading(edit(/bull /).replace('bull', bullet).getRegex())
.replace(/\|table/g, '')
.replace(/html/g, _htmlInterrupt)
.getRegex();
const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/;
const blockText = /^[^\n]+/;
const _blockLabel = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\\n]|\n(?![ \t]*\n))+/;
Expand Down Expand Up @@ -303,7 +303,7 @@ const blockPedantic: Record<BlockKeys, RegExp> = {
.replace('|list', '')
.replace('|html', '')
.replace('|tag', '')
.replace('lheading', lheading) // last, so the replacements above do not match inside it
.replace('lheading', lheadingPedantic) // last, so the replacements above do not match inside it
.getRegex(),
};

Expand Down
39 changes: 39 additions & 0 deletions test/specs/new/setext_noninterrupting_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<h1>a
2. b</h1>
<h2>a
0) b</h2>
<h1>a
123456789. b</h1>
<h1>a
2. b</h1>
<h1>a
+</h1>
<h1>a
1.</h1>
<p>a</p>
<ol>
<li>
<p>b
===</p>
</li>
<li>
<p>b
===</p>
</li>
</ol>
<p>a</p>
<ul>
<li>b
===</li>
</ul>
<p>a
2. b</p>
<p>===</p>
<p>a</p>
<table>
===
<h2>a
2. b</h2>
<h1>a
2. b
c</h1>
52 changes: 52 additions & 0 deletions test/specs/new/setext_noninterrupting_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
a
2. b
===

a
0) b
---

a
123456789. b
===

a
2. b
===

a
+
===

a
1.
===

a
1. b
===

2. b
===

a
- b
===

a
2. b

===

a
<table>
===

a
2. b
---

a
2. b
c
===
8 changes: 8 additions & 0 deletions test/specs/new/setext_noninterrupting_list_pedantic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>a
2. b
===</p>
<p>a</p>
<ul>
<li></li>
</ul>
<p>===</p>
11 changes: 11 additions & 0 deletions test/specs/new/setext_noninterrupting_list_pedantic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
pedantic: true
renderExact: true
---
a
2. b
===

a
+
===