Skip to content

Commit f056437

Browse files
authored
fix: Recognize setext headings whose first line starts with # (#4015)
A line like `#1 Goals` or `#hashtag` followed by a setext underline was rendered as a paragraph plus `<hr>` instead of a heading. A line only starts an ATX heading when the `#`s are followed by whitespace or EOL, so these are paragraph text and the underline makes a setext heading. The lheading ATX-interrupt check was bare ` {0,3}#{1,6}`, missing the `(?:\s|$)` that the paragraph and ATX heading rules already require.
1 parent 12bfa94 commit f056437

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎src/rules.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ const lheading = edit(lheadingCore)
115115
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt
116116
.replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
117117
.replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
118-
.replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt
118+
.replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/) // ATX heading can interrupt
119119
.replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
120120
.replace(/\|table/g, '') // table not in commonmark
121121
.getRegex();
@@ -124,7 +124,7 @@ const lheadingGfm = edit(lheadingCore)
124124
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt
125125
.replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
126126
.replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
127-
.replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt
127+
.replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/) // ATX heading can interrupt
128128
.replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
129129
.replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/) // table can interrupt
130130
.getRegex();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h2>#1 Goals</h2>
2+
<h1>#hashtag</h1>
3+
<h1>####### seven</h1>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#1 Goals
2+
---------
3+
4+
#hashtag
5+
===
6+
7+
####### seven
8+
===

0 commit comments

Comments
 (0)