feat(toc): add clickable anchor links and depth control#105
Merged
corylanou merged 3 commits intoMar 16, 2026
Merged
Conversation
Generate slug-based anchor links in TOC entries and inject id attributes on headings. Add depth attribute to limit heading levels and root attribute to exclude h1 headings. Handle duplicate headings with unique suffixed slugs. Support markdown TOC output format. Closes #80
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 28673d79d8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Preserve existing heading IDs instead of overwriting them - Fall back to "heading" slug for non-ASCII/empty heading text - Fix MD() to return generated markdown TOC instead of raw tags - Fix invalid HTML nesting for skipped heading levels
- Fix UniqueSlug collision when pre-seeded IDs overlap with generated suffixes - Remove empty placeholder <li> for skipped heading levels
corylanou
deleted the
issue-80-feat-toc-enhance-toc-tag-with-clickable-anchor-links-and-dep
branch
March 16, 2026 12:10
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.
Summary
#heading-slug) in TOC entries instead of index-based (#heading-N) linksidattributes on headings automatically when<toc>is presentdepthattribute to limit heading levels included (e.g.,depth="2"= h1+h2 only)rootattribute to exclude h1 headings from TOC (root="false")example,example-1,example-2)- [Heading](#slug)syntaxvscode.goTOC generation to use the new slug-based APICloses #80
Test Plan
Test_Slug— table-driven tests for slug generation (lowercase, special chars, spaces)Test_UniqueSlug— duplicate slug handling with counter suffixesTest_GenerateToC— basic TOC with nested headings and slug-based anchorsTest_GenerateToC_Depth— depth attribute filters out headings beyond limitTest_GenerateToC_NoRoot— root=false excludes h1 headings from TOCTest_GenerateToC_Duplicates— duplicate heading text gets unique IDsTest_ToC_MD— markdown output formatTest_ToC_MarshalJSON— JSON serialization with new depth/root fieldstestdata/auto/toc/hype.goldfor the auto module testrefs/includesfailure is a Go version mismatch, unrelated)