Fix empty sidebar entry for a heading that is a link#3146
Open
chatman-media wants to merge 1 commit into
Open
Conversation
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.
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.
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'sfilterHeader(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). Extendedheading-nav-markup.gomlwith a link-only heading plus assertions for both link cases.