Auto TOC Plugin
The auto TOC (Table of Contents) plugin automatically injects a table of contents section before the first## Heading in your documentation pages.
Features
- Automatic Insertion - No manual TOC creation needed
- Smart Placement - Inserts before the first H2 heading
- Internationalized - TOC title respects your locale settings
- Styled Component - Uses built-in
<Toc>component
How It Works
The plugin is a remark plugin that:- Scans the markdown AST for the first
## Heading(depth 2) - Inserts a TOC section before that heading
- Uses the
useTranslationhook for the “Table of Contents” title - Renders the built-in
<Toc>component
Configuration
The plugin is automatically enabled. No configuration is needed:packages/doom/src/plugins/auto-toc/index.ts:5-12
Implementation
The plugin transforms your markdown:packages/doom/src/plugins/auto-toc/remark-auto-toc.ts:6-19
Generated Output
For a page like this:Customization
Excluding from Rspress TOC
The generated TOC hasrp-toc-exclude class to prevent it from appearing in Rspress’s own TOC sidebar.
Translation
The TOC title is translatable. Add translations in your i18n configuration:i18n.yaml
Styling
The TOC container has thedoom-auto-toc class for custom styling:
When TOC is Not Generated
The plugin skips TOC generation if:- No
## Heading(H2) is found in the page - The page only has H1 or H3+ headings
- The page is too short to warrant a TOC
Disabling Auto TOC
To disable the auto TOC for specific pages, you can:- Use only H1 headings - The plugin requires an H2 to trigger
- Remove the plugin - Comment it out in your config:
- Create a custom plugin - Override the behavior for specific routes
Manual TOC
If you need more control, you can disable auto TOC and use Rspress’s manual TOC:Best Practices
- Use H2 for Major Sections - The plugin triggers on the first H2
- Consistent Heading Hierarchy - Follow H1 → H2 → H3 order
- Descriptive Headings - Headings appear in the TOC, make them clear
- Not Too Many Headings - Keep TOC manageable (5-10 items ideal)
Integration with Rspress
Doom’s auto TOC works alongside Rspress’s built-in TOC sidebar:- Auto TOC - In-page TOC before content
- Sidebar TOC - Right sidebar navigation