← Back to Pull requests

Preserve link text in sidebar heading navigation #3270

Open
saiv0n opened this pull request with 18 lines diff across 3 files
View on GitHub
saiv0n saiv0n commented on Nov 22, 2026 12:53 UTC
Author

Fixes #3260
Fixes #3126

When a heading contains a link (e.g. `## Like [this](example.com) or ## fzf), add_header_links() wraps the heading contents in <a class="header">, which produces nested <a> tags. Browsers automatically close the outer <a class="header"> before the inner link, leaving the link and any trailing text as siblings under the heading element rather than children of header.children[0].

Because toc.js called filterHeader(header.children[0], a), anything from the first link onward was dropped from the sidebar TOC (producing an empty anchor when the heading starts with a link).

This passes header itself to filterHeader and unwraps both mark and a elements (preserving their child nodes such as <code>), so the sidebar entry keeps the full heading content without nesting <a> tags. Added assertions to heading-nav-markup.goml` covering plain links, formatted links, and trailing text.

Diff: 18 lines (+13 / -5) across 3 files Reviewer: GuillaumeGomez Review duration: 12409m
All Vouch review confidence checks passed
Residual risk 0.02 = Change Risk (0.24) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.24 · 18 lines diff across 3 files
0.24
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.93 · 2 substantive comment(s)
0.93
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
90%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.176
Real PR Conversation Timeline
4 items
GuillaumeGomez GuillaumeGomez commented on code on Nov 25, 2026 11:07 UTC
Code Review
crates/mdbook-html/front-end/templates/toc.js.hbs:1
@@ -353,12 +353,12 @@ window.customElements.define('mdbook-sidebar-scrollbox', MDBookSidebarScrollbox)
         });
     }
 
-    // Takes the nodes from the given head and copies them over to the
+    // Takes the nodes from the given header and copies them over to the
     // destination, along with some filtering.
     function filterHeader(source, dest) {
         const clone = source.cloneNode(true);
-        clone.querySelectorAll('mark').forEach(mark => {
-            mark.replaceWith(...mark.childNodes);
+        clone.querySelectorAll('mark, a').forEach(el => {

This is the wrong fix. The sidebar renderer should only keep the <a> text, and remove the tag. It should not be done in the JS.

View changes since the review

GuillaumeGomez GuillaumeGomez requested changes on Nov 25, 2026 11:07 UTC
Changes Requested Reviewer

Requested changes.

rustbot rustbot commented on Nov 25, 2026 11:07 UTC
Contributor

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Assignees
saiv0n saiv0n
Labels
risk: low confidence: 90.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 23.5% (LOW) · Higher = larger blast radius
23.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 90.5% · Lower = rushed or shallow review
90.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 2.2% · Safe to merge
2.2%