Skip to content

fix(markdown) don't treat a thematic break as the start of bold text - #4485

Merged
joshgoebel merged 4 commits into
highlightjs:mainfrom
Mynk11:fix/markdown-thematic-break
Aug 10, 2026
Merged

fix(markdown) don't treat a thematic break as the start of bold text#4485
joshgoebel merged 4 commits into
highlightjs:mainfrom
Mynk11:fix/markdown-thematic-break

Conversation

@Mynk11

@Mynk11 Mynk11 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #3719. Picks up where #3909 left off, addressing @joshgoebel's review comments there.

*** on its own line is a thematic break, but BOLD was tried before HORIZONTAL_RULE in the top-level contains, so it matched ** and opened a strong span that swallowed the rest of the document.

Simply reordering was what stalled the previous attempt, because the old matcher (^[-\*]{3,}$) was loose enough to also eat the opening *** of ***bold italic***. So this does both: anchors the rule to a full line, then moves it ahead of BOLD/ITALIC.

const HORIZONTAL_RULE = { match: /^ {0,3}([-*_])[ \t]*(?:\1[ \t]*){2,}$/ };

Per spec 0.31.2: up to three leading spaces, then the same marker three or more times, separated and followed by spaces or tabs, and nothing else on the line.

On the earlier review comments:

  • _ style rule — covered; the marker is a capture group with a backreference, so ___ works and mixed runs like -*- correctly don't.
  • \s*$ — deliberately not used: \s matches \n, which would let a break swallow following blank lines. [ \t]* matches the spec's wording.
  • escaping * inside [] — not needed, dropped.

Behaviour is unchanged for ***bold italic***, **bold**, *italic*, setext headings (Heading / ---), and list bullets — all covered by the existing bold_italics and list tests, which still pass.

Out of scope, flagging it so it isn't a surprise: - - - still highlights as a bullet because LIST precedes HORIZONTAL_RULE. The spec says a thematic break wins there, but that's a separate precedence question and I'd rather not fold it into this fix. Happy to follow up.

npx mocha test → 1611 passing, 3 pending (was 1610 before the new test). Lint on src/languages/markdown.js is unchanged from main (one pre-existing spaced-comment error on the ENTITY comment, untouched here).

Checklist

  • Added markup tests (test/markup/markdown/horizontal_rule.{txt,expect.txt})
  • Updated CHANGES.md

@github-actions

Copy link
Copy Markdown

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change +26 B

View Changes
file base pr diff
es/core.min.js 8.22 KB 8.22 KB -2 B
es/highlight.min.js 8.22 KB 8.22 KB -2 B
es/languages/markdown.min.js 960 B 975 B +15 B
highlight.min.js 8.26 KB 8.26 KB -1 B
languages/markdown.min.js 959 B 975 B +16 B

@joshgoebel
joshgoebel merged commit 2a9ad7d into highlightjs:main Aug 10, 2026
19 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.

(markdown) Horizontal rule with 3 asterisks (***) causes bold text highlight

2 participants