Add table of contents sidebar with tree and scroll following - #48
Merged
Conversation
Introduce a right-side TOC panel for Markdown pages. A TOC toolbar button toggles panel visibility, which is persisted in localStorage (default off). Headings are extracted client-side from the rendered HTML; the button is auto-disabled when the page has no headings (e.g. text files). The panel is hidden in print output and falls back to an overlay on narrow screens. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Upgrade the flat list to a nested tree using heading levels, with expand/collapse carets that toggle independently from anchor navigation. The initial state expands only the top-most level so deeper headings stay folded until the user opens them. Track the current reading position on scroll and highlight the matching TOC entry, auto-expanding its ancestors. The active heading is resolved as the last heading whose top is at or above a reference line just below the sticky toolbar, which behaves symmetrically in both scroll directions (a prior IntersectionObserver band approach failed to update on upward scrolls between headings). TOC anchor clicks compute an offset from the live toolbar height before scrolling so the target heading is never hidden behind the sticky bar. Caret glyphs align vertically with the anchor text via a fixed line-height that matches the anchor's effective height. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.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.
Closes #47.
Summary
TOCbutton in the toolbar; visibility persists vialocalStorage(default off).Test plan
TOCbutton on a Markdown page; panel slides in/out and the state persists across reloads..txtfiles, directory listings, and error pages do not show TOC content (the toolbar button is disabled for.txt).🤖 Generated with Claude Code