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

242 stars

Best use case

markdown-toc is best used when you need a repeatable AI agent workflow instead of a one-off prompt. It is especially useful for teams working in multi. 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".

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

Users should expect a more consistent workflow output, faster repeated execution, and less time spent rewriting prompts from scratch.

Practical example

Example input

Use the "markdown-toc" skill to help with this workflow task. Context: 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".

Example output

A structured workflow result with clearer steps, more consistent formatting, and an output that is easier to reuse in the next run.

When to use this skill

  • Use this skill when you want a reusable workflow rather than writing the same prompt again and again.

When not to use this skill

  • Do not use this when you only need a one-off answer and do not need a reusable workflow.
  • Do not use it if you cannot install or maintain the related files, repository context, or supporting tools.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/markdown-toc/SKILL.md --create-dirs "https://raw.githubusercontent.com/aiskillstore/marketplace/main/skills/emasoft/markdown-toc/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/markdown-toc/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How markdown-toc Compares

Feature / Agentmarkdown-tocStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

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

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 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 Skills

woocommerce-markdown

242
from aiskillstore/marketplace

Guidelines for creating and modifying markdown files in WooCommerce. Use when writing documentation, README files, or any markdown content.

obsidian-markdown

242
from aiskillstore/marketplace

Create and edit Obsidian Flavored Markdown with wikilinks, embeds, callouts, properties, and other Obsidian-specific syntax. Use when working with .md files in Obsidian, or when the user mentions wikilinks, callouts, frontmatter, tags, embeds, or Obsidian notes.

baoyu-url-to-markdown

242
from aiskillstore/marketplace

Fetch any URL and convert to markdown using Chrome CDP. Supports two modes - auto-capture on page load, or wait for user signal (for pages requiring login). Use when user wants to save a webpage as markdown.

baoyu-markdown-to-html

242
from aiskillstore/marketplace

Converts Markdown to styled HTML with WeChat-compatible themes. Supports code highlighting, math, PlantUML, footnotes, alerts, and infographics. Use when user asks for "markdown to html", "convert md to html", "md转html", or needs styled HTML output from markdown.

baoyu-format-markdown

242
from aiskillstore/marketplace

Formats plain text or markdown files with frontmatter, titles, summaries, headings, bold, lists, and code blocks. Use when user asks to "format markdown", "beautify article", "add formatting", or improve article layout. Outputs to {filename}-formatted.md.

baoyu-danger-x-to-markdown

242
from aiskillstore/marketplace

Convert X (Twitter) tweet or article URL to markdown. Uses reverse-engineered X API (private). Requires user consent before use.

markdown-pro

242
from aiskillstore/marketplace

Professional Markdown documentation skill for creating polished README files, changelogs, contribution guides, and technical documentation. Use for: (1) README generation with badges and sections, (2) Automated changelog from git history, (3) Table of contents generation, (4) Contribution guidelines, (5) Technical documentation formatting, (6) Code documentation with syntax highlighting

markdown-url

242
from aiskillstore/marketplace

Route any website you need to visit through markdown.new by prefixing the URL. **WHEN TO USE:** - You would normally open a website link to read content (docs, blog posts, changelogs, GitHub issues, etc.) - You need a cleaner, Markdown-friendly view for copying notes or summarizing

markdown

242
from aiskillstore/marketplace

Markdown linting and automated fixing using markdownlint-cli2. Use when Claude needs to: (1) Check markdown files for style issues, (2) Fix markdown formatting problems, (3) Ensure markdown follows best practices, (4) Validate markdown documents, or (5) Apply consistent markdown styling

azure-quotas

242
from aiskillstore/marketplace

Check/manage Azure quotas and usage across providers. For deployment planning, capacity validation, region selection. WHEN: "check quotas", "service limits", "current usage", "request quota increase", "quota exceeded", "validate capacity", "regional availability", "provisioning limits", "vCPU limit", "how many vCPUs available in my subscription".

DevOps & Infrastructure

raindrop-io

242
from aiskillstore/marketplace

Manage Raindrop.io bookmarks with AI assistance. Save and organize bookmarks, search your collection, manage reading lists, and organize research materials. Use when working with bookmarks, web research, reading lists, or when user mentions Raindrop.io.

Data & Research

zlibrary-to-notebooklm

242
from aiskillstore/marketplace

自动从 Z-Library 下载书籍并上传到 Google NotebookLM。支持 PDF/EPUB 格式,自动转换,一键创建知识库。