feat(repo): add a GitHub-style outline popup to rendered Markdown #221
No reviewers
Labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
codefloe/forgejo-codefloe!221
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/markdown-outline"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Rendered Markdown files and READMEs get an Outline button in the file header, like GitHub's.
It opens a popup listing the document's headings, nested by level, with a filter box; clicking a heading jumps to it.
Upstream only shows a table of contents in the wiki, although the Markdown renderer builds the heading list for every document and the file view discards it.
What it adds
routers/web/repo/view.go: one call inmarkupRender, so file views, READMEs on the repository home and other rendered markup files all get the outline.routers/web/repo/view_codefloe.go: renderRenderContext.SidebarTocNodeasFileOutline, the same node the wiki sidebar uses, so nothing is parsed twice; move each sub-list into its parent item first, becausemodules/markup/markdown/toc.goemits<ul>directly inside<ul>(axe'slistrule flags it).templates/repo/codefloe_file_outline.tmpl, included in the header oftemplates/repo/view_file.tmpl: the button, in the sameui compact icon buttonsgroup markup as the source/rendered toggle so it matches its size.templates/repo/codefloe_file_outline_popup.tmpl, included at the end of the file view: the hidden popup, kept out ofh4.file-headerbecause upstream'sTestViewRepoDirectoryReadmeexpects the header text to be the file name.web_src/js/codefloe/file-outline.js: a delegated, lazily created tippy popup with an accessible name; the filter keeps the parents of a matching subheading visible and shows "No matching headings" when nothing matches; clicking a heading closes the popup.web_src/css/codefloe/file-outline.css: compact nested list with theme variables, checked incodefloe-*andcodefloe-tide-*light and dark.options/locale_next/locale_en-US.json: three strings.README.md: custom changes row.Behaviour
?display=source) and only when the document has headings.include_toc: falsehides the button,include_toc: mainkeeps the inline table of contents and shows no button.Tests
tests/integration/codefloe_file_outline_test.go: link targets and texts, HTML escaping of heading text, valid nesting including a skipped heading level, the README on the repository home, and no button for source view,include_toc: false/main, a file without headings and a non-Markdown file.web_src/js/codefloe/file-outline.test.js: filter behaviour, 6 tests.tests/e2e/codefloe-file-outline.test.e2e.ts: open, focus, axe scan, filter, empty state, jump to a heading and popup close, in chromium, firefox and Mobile Chrome.layout-shift,clipboard-copy,codefloe-tide-theme,markup,repo-wiki).repo-code›Readable diff(firefox only) fails intermittently withChunkLoadError: Loading chunk repo-switcher failed; an untouched base build fails it the same way.a0d54ec2ee9b2f077fae9b2f077faef977140014