Skip to content

feat(toc): add clickable anchor links and depth control#105

Merged
corylanou merged 3 commits into
mainfrom
issue-80-feat-toc-enhance-toc-tag-with-clickable-anchor-links-and-dep
Mar 16, 2026
Merged

feat(toc): add clickable anchor links and depth control#105
corylanou merged 3 commits into
mainfrom
issue-80-feat-toc-enhance-toc-tag-with-clickable-anchor-links-and-dep

Conversation

@corylanou

Copy link
Copy Markdown
Member

Summary

  • Generate slug-based anchor links (#heading-slug) in TOC entries instead of index-based (#heading-N) links
  • Inject id attributes on headings automatically when <toc> is present
  • Add depth attribute to limit heading levels included (e.g., depth="2" = h1+h2 only)
  • Add root attribute to exclude h1 headings from TOC (root="false")
  • Handle duplicate headings with unique suffixed slugs (example, example-1, example-2)
  • Support markdown TOC output format with - [Heading](#slug) syntax
  • Update vscode.go TOC generation to use the new slug-based API

Closes #80

Test Plan

  • Test_Slug — table-driven tests for slug generation (lowercase, special chars, spaces)
  • Test_UniqueSlug — duplicate slug handling with counter suffixes
  • Test_GenerateToC — basic TOC with nested headings and slug-based anchors
  • Test_GenerateToC_Depth — depth attribute filters out headings beyond limit
  • Test_GenerateToC_NoRoot — root=false excludes h1 headings from TOC
  • Test_GenerateToC_Duplicates — duplicate heading text gets unique IDs
  • Test_ToC_MD — markdown output format
  • Test_ToC_MarshalJSON — JSON serialization with new depth/root fields
  • Updated testdata/auto/toc/hype.gold for the auto module test
  • All existing tests continue to pass (pre-existing refs/includes failure is a Go version mismatch, unrelated)

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread heading.go
Comment thread toc.go Outdated
- 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
corylanou merged commit 43d2f22 into main Mar 16, 2026
3 checks passed
@corylanou
corylanou deleted the issue-80-feat-toc-enhance-toc-tag-with-clickable-anchor-links-and-dep branch March 16, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(toc): enhance <toc> tag with clickable anchor links and depth control

1 participant