Generate Table of Contents
Generate or update a markdown table of contents for a documentation file.
Instructions
- •
Read the target file
- •
Extract all headers (H2 and H3 only):
- •Skip H1 (document title)
- •Skip H4+ (too detailed for TOC)
- •
Generate anchor links:
- •Convert header text to lowercase
- •Replace spaces with hyphens
- •Remove special characters
- •Example:
## Getting Started->#getting-started
- •
Format the TOC:
markdown
## Table of Contents 1. [Section One](#section-one) 2. [Section Two](#section-two) - [Subsection A](#subsection-a) - [Subsection B](#subsection-b) 3. [Section Three](#section-three)
- •Insert or replace:
- •If
## Table of Contentsexists, replace its contents - •Otherwise, insert after the introduction paragraph (first paragraph after H1)
- •If
TOC Rules
- •Include H2 headers as numbered items
- •Include H3 headers as sub-bullets under their parent H2
- •Do not include H4+ headers
- •Do not include "Table of Contents" itself
- •Skip special sections: "Related Resources", "See Also", "References"
Example
Input file:
markdown
# My Guide This guide explains something important. ## Prerequisites Content... ## Installation Content... ### Using pip Content... ### Using conda Content... ## Configuration Content... ## Related Resources Links...
Generated TOC:
markdown
## Table of Contents 1. [Prerequisites](#prerequisites) 2. [Installation](#installation) - [Using pip](#using-pip) - [Using conda](#using-conda) 3. [Configuration](#configuration)
Example Usage
code
/doc-toc docs/guides/getting-started.md /doc-toc example/api/authentication.md