fix(preview): make footnote & heading anchor links navigate (#69) - #89
Merged
Conversation
Footnote refs/back-refs render as in-page anchors (`#…fn-1` ⇄ `#…fnref-1`), but the preview's click handler ended in a catch-all preventDefault that swallowed them — and native hash navigation doesn't scroll a target inside the preview's own overflow:auto container anyway, so footnotes did nothing in preview/split. Resolve `#`-fragment anchors against the preview container and scroll the target into view, with a brief accent highlight. Works both ways (ref → definition and the ↩ back-ref → reference) and also fixes heading/TOC anchor links. Fixes #69
Closed
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.
Fixes #69 — footnotes did nothing in the (split) preview, and should link both ways.
Cause
Footnote refs/back-refs render as in-page anchors (
#…fn-1⇄#…fnref-1). The preview's click handler ended in a catch-alle.preventDefault()that swallowed those clicks — and the browser's native hash navigation doesn't scroll a target that lives inside the preview's ownoverflow:autocontainer anyway. (The sanitizer keeps thehref/id, so the markup was fine — purely a navigation gap.)Fix
When a clicked anchor's
hrefis a#-fragment, resolve the target by id within the preview container andscrollIntoViewit, with a brief accent highlight so the jump is visible. Works both ways — ref → definition and the↩back-ref → reference — and also fixes heading/TOC anchor links.Verification
06 — Callouts and Footnotesin Split/Preview (clicking a footnote jumps to its definition and back).npm run typecheckpasses.One-spot change in
Preview.tsx; independent of #88 (different region of the same file).