Skip to content

fix: Recognize setext headings whose first line starts with ##4015

Merged
UziTech merged 1 commit into
markedjs:masterfrom
hong4rc:fix/setext-hash-prefix
Jul 14, 2026
Merged

fix: Recognize setext headings whose first line starts with ##4015
UziTech merged 1 commit into
markedjs:masterfrom
hong4rc:fix/setext-hash-prefix

Conversation

@hong4rc

@hong4rc hong4rc commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

A line like #1 Goals or #hashtag followed by a setext underline is rendered as a paragraph plus an <hr> instead of a heading:

marked.parse('#1 Goals\n---------');  // <p>#1 Goals</p>\n<hr>

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 #1 is ordinary paragraph text — which means the --------- beneath it makes a setext heading.

The lheading rule 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 ATX heading rule itself ((?=\s|$)); this just brings lheading/lheadingGfm in 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.

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.
@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown

@hong4rc is attempting to deploy a commit to the MarkedJS Team on Vercel.

A member of the Team first needs to authorize it.

@UziTech UziTech left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! 💯

@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marked-website Ready Ready Preview, Comment Jul 12, 2026 5:19am

Request Review

@UziTech UziTech merged commit f056437 into markedjs:master Jul 14, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants