From 0b8fd2f26c621718f20c8511511900752fe22820 Mon Sep 17 00:00:00 2001 From: patakuti Date: Sat, 18 Apr 2026 09:57:42 +0900 Subject: [PATCH 1/2] Add table of contents sidebar (MVP) 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 --- README.md | 1 + internal/template/template.go | 7 +++ internal/template/toc.go | 111 ++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 internal/template/toc.go diff --git a/README.md b/README.md index 29ce349..042a17d 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ How markdown-proxy compares to other Markdown viewing tools: - Print: browser print with clean filename (toolbar hidden in print output) - Source: link to original URL on remote server (remote pages only) - Multiple CSS themes (GitHub, Simple, Dark) with switching UI +- Table of contents sidebar: toggle `TOC` in the toolbar to open a right-side panel with auto-extracted headings; visibility persists per browser (localStorage) - Live reload for local files (auto-refreshes browser on file changes) - Directory listing for local files - Line anchor links: `[text](foo.md:12)` or `` links navigate to specific source lines with highlighting (Markdown and text files) diff --git a/internal/template/template.go b/internal/template/template.go index edc2f9d..7f99c93 100644 --- a/internal/template/template.go +++ b/internal/template/template.go @@ -87,6 +87,7 @@ const markdownPageTplHead = ` + ` const markdownPageTplTail = ` @@ -99,6 +100,7 @@ const markdownPageTplTail = ` {{if .SourceURL}}Source{{end}} Print + TOC