Skip to content

feat: add smooth scroll for footnote references#156

Merged
k1LoW merged 6 commits intomainfrom
fix-footnote-smooth-scroll
Mar 31, 2026
Merged

feat: add smooth scroll for footnote references#156
k1LoW merged 6 commits intomainfrom
fix-footnote-smooth-scroll

Conversation

@k1LoW
Copy link
Copy Markdown
Owner

@k1LoW k1LoW commented Mar 31, 2026

Summary

  • Fix broken footnote navigation caused by rehype-sanitize doubling the user-content- ID prefix on footnote elements. Add a rehypeStripClobberPrefix plugin that strips the prefix from remark-gfm footnote IDs before rehype-sanitize re-adds it, preserving DOM-clobbering protection.
  • Add smooth scroll behavior to all internal hash links (#-prefixed), so clicking a footnote reference ([^1]) smoothly scrolls to its definition and the backlink (↩) scrolls back.
  • Respect prefers-reduced-motion for smooth scroll (hash links and ToC heading clicks).
  • Skip smooth scroll on modified clicks (ctrl/cmd/shift/alt) to preserve browser default behavior.

Closes #155

Fix broken footnote navigation caused by rehype-sanitize doubling the
`user-content-` ID prefix (remark-gfm already generates prefixed IDs).
Set `clobberPrefix: ""` in the sanitize schema to prevent the clash.

Add smooth scroll behavior to all internal hash links (#-prefixed),
so clicking a footnote reference smoothly scrolls to its definition
and the backlink (↩) scrolls back to the reference.

Closes #155
@k1LoW k1LoW self-assigned this Mar 31, 2026
@k1LoW k1LoW added the bug Something isn't working label Mar 31, 2026
Preserve browser back-button navigation through footnote/heading links,
matching native anchor link behavior.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

This comment was marked as outdated.

k1LoW added 2 commits March 31, 2026 14:26
- Preserve rehype-sanitize DOM-clobbering protection by keeping the
  default clobberPrefix and adding a rehype plugin that strips the
  user-content- prefix from remark-gfm footnote IDs before sanitize
  re-adds it (avoiding double-prefixed IDs without dropping security).
- Skip smooth scroll on modified clicks (ctrl/cmd/shift/alt) so
  browser default behavior (e.g., open in new tab) is preserved.
- Respect prefers-reduced-motion for all smooth scroll navigation
  (hash links in MarkdownViewer and ToC heading clicks in App).
@github-actions

This comment has been minimized.

This comment was marked as outdated.

@github-actions

This comment has been minimized.

This comment was marked as outdated.

Limit rehypeStripClobberPrefix to remark-gfm footnote IDs (fn-*, fnref-*,
footnote-label) to avoid collisions with raw HTML user-content-* IDs.
@k1LoW k1LoW requested a review from Copilot March 31, 2026 05:55
@github-actions
Copy link
Copy Markdown
Contributor

Code Metrics Report

main (32a32f7) #156 (23a155e) +/-
Coverage 57.5% 57.1% -0.4%
Code to Test Ratio 1:0.5 1:0.5 -0.1
Test Execution Time 29s 31s +2s
Details
  |                     | main (32a32f7) | #156 (23a155e) |  +/-  |
  |---------------------|----------------|----------------|-------|
- | Coverage            |          57.5% |          57.1% | -0.4% |
  |   Files             |             40 |             40 |     0 |
  |   Lines             |           3518 |           3538 |   +20 |
- |   Covered           |           2023 |           2021 |    -2 |
- | Code to Test Ratio  |          1:0.5 |          1:0.5 |  -0.1 |
  |   Code              |           5642 |           5682 |   +40 |
  |   Test              |           2961 |           2961 |     0 |
- | Test Execution Time |            29s |            31s |   +2s |

Code coverage of files in pull request scope (71.1% → 70.1%)

Files Coverage +/- Status
internal/frontend/src/components/MarkdownViewer.tsx 32.7% -2.4% modified
internal/server/server.go 78.3% -0.2% affected

Reported by octocov

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

@k1LoW k1LoW merged commit 5c9fc8f into main Mar 31, 2026
7 checks passed
@k1LoW k1LoW deleted the fix-footnote-smooth-scroll branch March 31, 2026 06:06
@github-actions github-actions bot mentioned this pull request Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: add smooth scroll to footnote references

2 participants