feat(repo): add extractToc remark plugin for mobile table of contents#8419
Closed
feat(repo): add extractToc remark plugin for mobile table of contents#8419
Conversation
Add a remark plugin that extracts structured TOC data from markdown
headings and injects it into YAML frontmatter. This enables the docs
rendering engine to access pre-computed TOC data for rendering an
expandable mobile table of contents.
The plugin:
- Extracts h2-h4 headings with configurable depth range
- Supports custom heading IDs from MDX annotations ({{ id: 'custom' }})
- Generates URL-safe slugs for anchor links
- Injects structured toc array into frontmatter
Ref: DOCS-11605
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Contributor
Author
|
testing out cursor cloud agents started in linear - ran in the wrong repo 🤦 |
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.
Description
Adds a remark plugin (
extractToc) that extracts structured table of contents (TOC) data from markdown headings and injects it into YAML frontmatter. This is the data layer needed to support an expandable mobile TOC on the docs site.Context: The table of contents for each docs page is currently hidden on mobile (DOCS-11605). To render an expandable mobile TOC, the docs rendering engine needs easy access to structured heading data. This plugin pre-computes that data during the build pipeline so the rendering engine doesn't need to re-parse the MDX.
What the plugin does
minDepth/maxDepth)## Heading {{ id: 'custom-id' }})tocarray into the YAML frontmatterOutput format
Integration with clerk-docs build pipeline
This plugin is designed to be integrated into the
clerk-docsbuild pipeline (scripts/build-docs.ts) as a remark plugin:Remaining work
After this plugin is integrated into
clerk-docs, the rendering engine inclerk/clerkneeds to:tocfrontmatter fieldTests
16 unit tests covering:
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Linear Issue: DOCS-11605