fix: Recognize setext headings whose first line starts with ##4015
Merged
Conversation
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.
|
@hong4rc is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
styfle
approved these changes
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A line like
#1 Goalsor#hashtagfollowed by a setext underline is rendered as a paragraph plus an<hr>instead of a heading:Both commonmark.js and markdown-it produce
<h2>#1 Goals</h2>here, and that matches the CommonMark spec: a line only starts an ATX heading when the#s are followed by a space, a tab, or the end of the line, so#1is ordinary paragraph text — which means the---------beneath it makes a setext heading.The
lheadingrule already knows other blocks can interrupt a setext heading, but its ATX check is{0,3}#{1,6}, which matches any line that merely starts with#and misses the "followed by whitespace" requirement. marked's own paragraph rules already get this right ({0,3}#{1,6}(?:\s|$)), as does the ATXheadingrule itself ((?=\s|$)); this just bringslheading/lheadingGfmin line with them.Valid ATX headings are unaffected —
# Real\n===still renders<h1>Real</h1>followed by<p>===</p>— and the full spec suite passes with the added fixture.