Skip to content

Commit

Permalink
fix: fix setext heading interupts (#3210)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Mar 6, 2024
1 parent d61c266 commit d848445
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ const fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\
const hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
const heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
const bullet = /(?:[*+-]|\d{1,9}[.)])/;
const lheading = edit(/^(?!bull )((?:.|\n(?!\s*?\n|bull ))+?)\n {0,3}(=+|-+) *(?:\n+|$)/)
const lheading = edit(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/)
.replace(/bull/g, bullet) // lists can interrupt
.replace(/blockCode/g, / {4}/) // indented code blocks can interrupt
.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}/) // ATX heading can interrupt
.replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
.getRegex();
const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
const blockText = /^[^\n]+/;
Expand Down
12 changes: 12 additions & 0 deletions test/specs/new/setext_no_blankline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<pre><code>indented code block
</code></pre>
<p>=</p>
<p>fenced code block</p>
<pre><code>=
</code></pre>
<blockquote><h1>blockquote</h1>
</blockquote>
<h3>heading</h3>
<p>=</p>
<html>
=
16 changes: 16 additions & 0 deletions test/specs/new/setext_no_blankline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
indented code block
=

fenced code block
```
=
```

> blockquote
=

### heading
=

<html>
=

0 comments on commit d848445

Please sign in to comment.