mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
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.
This commit is contained in:
+2
-2
@@ -115,7 +115,7 @@ const lheading = edit(lheadingCore)
|
||||
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // 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(/heading/g, / {0,3}#{1,6}(?:\s|$)/) // ATX heading can interrupt
|
||||
.replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
|
||||
.replace(/\|table/g, '') // table not in commonmark
|
||||
.getRegex();
|
||||
@@ -124,7 +124,7 @@ const lheadingGfm = edit(lheadingCore)
|
||||
.replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // 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(/heading/g, / {0,3}#{1,6}(?:\s|$)/) // ATX heading can interrupt
|
||||
.replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
|
||||
.replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/) // table can interrupt
|
||||
.getRegex();
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<h2>#1 Goals</h2>
|
||||
<h1>#hashtag</h1>
|
||||
<h1>####### seven</h1>
|
||||
@@ -0,0 +1,8 @@
|
||||
#1 Goals
|
||||
---------
|
||||
|
||||
#hashtag
|
||||
===
|
||||
|
||||
####### seven
|
||||
===
|
||||
Reference in New Issue
Block a user