Skip to content

Fix empty sidebar entry for a heading that is a link#3146

Open
chatman-media wants to merge 1 commit into
rust-lang:masterfrom
chatman-media:fix/sidebar-link-heading-empty-anchor
Open

Fix empty sidebar entry for a heading that is a link#3146
chatman-media wants to merge 1 commit into
rust-lang:masterfrom
chatman-media:fix/sidebar-link-heading-empty-anchor

Conversation

@chatman-media

Copy link
Copy Markdown

Closes #3126.

When a heading's whole content is a Markdown link (e.g. ## [fzf](url)), the injected <a class="header"> permalink wraps the link, producing nested anchors in the generated HTML. Browsers hoist the inner link out as a sibling of the (now empty) permalink anchor, so the sidebar's filterHeader(header.children[0], …) copied the empty anchor and rendered a blank entry.

The sidebar entry is now built from the whole heading with the permalink anchor unwrapped, so the heading text (and any embedded link) comes through. This also fixes the previously-silent loss of an embedded link in headings like ## Heading with a [link](…).

Verified the parsed-DOM behavior and the fix against jsdom for normal / markup / <mark> / link-only / text+link headings (link-only goes from "" to "fzf"; others unchanged). Extended heading-nav-markup.goml with a link-only heading plus assertions for both link cases.

When a heading's entire content is a Markdown link (e.g. `## [fzf](url)`),
mdBook wraps the heading content in an injected `<a class="header">`
permalink anchor, producing nested anchors in the generated HTML. The
browser hoists the inner link out as a sibling of the (now empty)
permalink anchor, so copying `header.children[0]` into the sidebar
yielded an empty anchor.

Build the sidebar entry from the whole heading and unwrap the permalink
anchor, so the heading text (and any embedded link) is preserved.
@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sidebar header navigation renders empty anchor when heading is a Markdown link

2 participants