Markdown code span regex crosses blank-line/paragraph boundaries, swallowing a subsequent header's highlighting #1325
denysshnurenko
started this conversation in
^ Lexer Requests and Bugs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
What happened
An inline code span (single backtick) whose closing backtick appears after
a header, separated by a blank line, gets matched as one greedy token that
swallows the header text — so the header loses its heading-color styling.
Repro:
Expected: "## Swallowed Header" renders with heading styling.
Actual: it's consumed into the code-span token and rendered as plain
backtick-string text instead.
Root cause
lexers/markdown.go:102:[^]` matches newlines by default in Go's RE2 engine, so this rule greedilymatches across blank lines / paragraph and block boundaries. Per CommonMark,
a code span should not cross a blank line — this rule has no such bound.
Related
#1267 reports a similar symptom (list-item code blocks losing highlighting)
and was closed as "completed", but the exact same regex is still present at
HEAD (
af5ff891, 2026-06-17, is the only recent commit touchingmarkdown.go, and it's an unrelated Iterator→iter.Seq refactor) — so whatever
closed #1267 doesn't look like it touched this rule. Might be worth
re-checking whether #1267 is actually resolved, since it and this report
look like they share the same underlying cause.
Context
Found via revdiff (a diff-review TUI that uses chroma for markdown
rendering) — see umputun/revdiff#260 for the original report and the
maintainer's diagnosis that traced it back to this rule.
Environment
All reactions