fix(html): avoid nested anchors in headings with links#3100
Open
leno23 wants to merge 3 commits into
Open
Conversation
Insert an empty header anchor as the first child of each heading instead of wrapping all heading content. This fixes invalid HTML when headings contain markdown links or other inline anchors. Fixes rust-lang#221. Co-authored-by: Cursor <cursoragent@cursor.com>
Update toc.js to copy heading text from the full heading element when the `.header` anchor is empty, fixing sidebar navigation after the nested-anchor fix for issue rust-lang#221. Co-authored-by: Cursor <cursoragent@cursor.com>
Use empty prepended header links only when a heading or definition term already contains an `<a>` from markdown. Other headings keep wrapping text in the header link so search highlighting and GUI tests behave as before. Update snapshots for the linked-heading case (issue rust-lang#221). Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
Fixes invalid nested
<a>elements when headings (or definition terms) contain markdown links.<a>from markdown, prepend an empty<a class="header">as the first child so permalink and inline links do not nest.toc.jsso sidebar “on this page” navigation still shows full heading text when the empty header link is used.Example (heading with link):
Fixes #221.
Test plan
rendering/header_linkswith a heading containing a markdown linkdefinition_listssnapshot for<dt>terms with linkscargo test -p mdbook --test testsuite(110 passed)