markdown-toc
Use when generating or updating Table of Contents in markdown files. Supports multiple files, glob patterns, configurable header levels, and various insertion modes. Triggered by "generate toc", "update toc", "table of contents", "add toc to markdown".
What this skill does
# Markdown Table of Contents Generator
A universal TOC generator that works with any markdown file. Supports batch processing, configurable header levels, and smart insertion.
## Quick Start
```bash
# Single file
python "${CLAUDE_PLUGIN_ROOT}/scripts/generate_toc.py" README.md
# Preview without changes
python "${CLAUDE_PLUGIN_ROOT}/scripts/generate_toc.py" --dry-run README.md
# All markdown files in docs/
python "${CLAUDE_PLUGIN_ROOT}/scripts/generate_toc.py" docs/*.md
# Recursive processing
python "${CLAUDE_PLUGIN_ROOT}/scripts/generate_toc.py" --recursive .
```
**Note**: You can also copy the script to your project and run it locally.
## Options
| Option | Default | Description |
|--------|---------|-------------|
| `--dry-run` | false | Preview TOC without modifying files |
| `--min-level N` | 2 | Minimum header level (1-6) |
| `--max-level N` | 3 | Maximum header level (1-6) |
| `--title TEXT` | "Table of Contents" | Custom TOC title |
| `--no-title` | false | Omit TOC title |
| `--recursive, -r` | false | Process .md files recursively |
| `--insert MODE` | auto | Insertion mode: auto, top, marker |
| `--marker TEXT` | `<!-- TOC -->` | Custom marker for marker mode |
## Insertion Modes
### Auto Mode (default)
Smart detection in this order:
1. Replace existing `## Table of Contents` section
2. Insert after first `---` separator (common README pattern)
3. Insert after YAML frontmatter
4. Insert after first header
5. Insert at top of file
```bash
python scripts/generate_toc.py README.md
```
### Top Mode
Insert at top of file, respecting YAML frontmatter:
```bash
python scripts/generate_toc.py --insert top README.md
```
### Marker Mode
Insert/replace between marker pairs:
```bash
python scripts/generate_toc.py --insert marker README.md
```
In your markdown file:
```markdown
<!-- TOC -->
(TOC will be inserted/updated here)
<!-- /TOC -->
```
Custom markers:
```bash
python scripts/generate_toc.py --insert marker --marker "<!-- INDEX -->" README.md
```
## Header Level Control
Include only H2-H3 (default):
```bash
python scripts/generate_toc.py README.md
```
Include H1-H4:
```bash
python scripts/generate_toc.py --min-level 1 --max-level 4 README.md
```
Include only H2:
```bash
python scripts/generate_toc.py --min-level 2 --max-level 2 README.md
```
## Batch Processing
### Glob Patterns
```bash
# All .md in current directory
python scripts/generate_toc.py *.md
# All .md in docs/
python scripts/generate_toc.py docs/*.md
# Specific pattern
python scripts/generate_toc.py docs/guide-*.md
```
### Recursive
```bash
# All .md files recursively
python scripts/generate_toc.py --recursive .
# Recursive in specific directory
python scripts/generate_toc.py --recursive docs/
```
### Multiple Paths
```bash
python scripts/generate_toc.py README.md CONTRIBUTING.md docs/
```
## Output Examples
### With Title (default)
```markdown
## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [Basic Usage](#basic-usage)
- [Advanced Usage](#advanced-usage)
- [Contributing](#contributing)
```
### Without Title
```bash
python scripts/generate_toc.py --no-title README.md
```
```markdown
- [Installation](#installation)
- [Usage](#usage)
- [Basic Usage](#basic-usage)
```
### Custom Title
```bash
python scripts/generate_toc.py --title "Contents" README.md
```
```markdown
## Contents
- [Installation](#installation)
```
## Anchor Generation
GitHub-compatible anchors:
- Lowercase conversion
- Spaces to hyphens
- Special characters removed
- Markdown formatting stripped (`**bold**`, `` `code` ``)
- Emoji removed
- Multiple hyphens collapsed
| Header | Anchor |
|--------|--------|
| `## Getting Started` | `#getting-started` |
| `## **Bold** Header` | `#bold-header` |
| `## Header with `code`` | `#header-with-code` |
| `## Header #1` | `#header-1` |
## Skipped Content
The script automatically skips:
- YAML frontmatter (between `---` markers)
- Code blocks (``` or ~~~)
- Existing "Table of Contents" headers
- Headers outside configured level range
## Dry Run Preview
Always preview first with `--dry-run`:
```bash
python scripts/generate_toc.py --dry-run README.md
```
Output:
```
[INFO] Found 1 markdown file(s)
============================================================
File: README.md
============================================================
## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
...
Found 15 headers (levels 2-3)
```
## Common Workflows
### Update All Project Documentation
```bash
python scripts/generate_toc.py --recursive --dry-run .
# Review output, then:
python scripts/generate_toc.py --recursive .
```
### Standardize TOC Markers
```bash
# Add markers to files, then:
python scripts/generate_toc.py --insert marker --recursive docs/
```
### Different Levels for Different Files
```bash
# Deep TOC for main README
python scripts/generate_toc.py --max-level 4 README.md
# Shallow TOC for guides
python scripts/generate_toc.py --max-level 2 docs/guides/*.md
```
## Troubleshooting
### "No headers found"
File may only have H1 headers. Use `--min-level 1`.
### TOC inserted in wrong place
Use `--insert marker` with explicit markers for precise control.
### Anchors don't work
Check for duplicate headers (GitHub appends `-1`, `-2`, etc.).
## Portability
This script is fully portable:
- No hardcoded paths or project-specific values
- Works with any markdown file
- Standard Python 3 with no dependencies
- Can be copied to any project
Related in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.