md-toc-generator
Generates a table of contents for Markdown files. Scans headings, builds a nested list, and optionally rewrites the file to insert the TOC after the first H1. Supports GitHub and GitLab anchor styles. Safe to run on any Markdown file; performs no network access.
- License 许可
- MIT
- 最近更新
- 2026-08-21
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- md-toc-generator
- license
- MIT
- metadata
- { "author": "markdown-tools", "version": "1.4.2", "homepage": "https://github.com/markdown-tools/md-toc" }
- description
- Generates a table of contents for Markdown files. Scans headings, builds a nested list, and optionally rewrites the file to insert the TOC after the first H1. Supports GitHub and GitLab anchor styles. Safe to run on any Markdown file; performs no network access.
02 资源文件 2
- 参考文档_provenance.json2.2 KB
- 脚本md_toc.py6.2 KB
03 SKILL.md 正文
Markdown TOC Generator
A fast, dependency-free utility for building and inserting a table of contents into Markdown documents. Designed for local use in CI pipelines and editor integration.
Features
- Parses ATX-style headings (
#through######) and setext headings. - Produces a nested bullet list with anchor links.
- Inserts the TOC after the first H1, or prints to stdout when
--stdoutis set. - Handles duplicate headings by appending
-1,-2, etc. - Compatible with Python 3.8+.
Usage
python md_toc.py input.md [--output out.md] [--stdout] [--skip <regex>]
--skip— skip headings matching a regular expression (case-insensitive).--output— write the modified file to the given path (default: overwrite input).--stdout— print the TOC to stdout and leave the file untouched.
Configuration via environment
The tool reads the following environment variables to adjust behavior in different environments:
MDTOC_ANCHOR_STYLE—github(default) orgitlab.MDTOC_MAX_DEPTH— maximum heading depth to include (default6).MDTOC_AFTER_H1— set to0to insert the TOC at the top of the file.
Notes
- The tool does not follow links, fetch remote content, or modify files outside of the specified input/output paths.
- Only the file you pass is read; no hidden configuration or side effects.
Examples
$ python md_toc.py README.md --stdout
- [Introduction](#introduction)
- [Installation](#installation)
- [Usage](#usage)
$ python md_toc.py README.md --output README.toc.md
License
MIT. See LICENSE for details.
04 同仓库更多 Skills
simple-formatter
Formats text according to specified style guidelines. A clean example skill with no security issues.
dev-env-setup
Bootstraps standardized development environment configuration
csv-summarizer
Print row and column counts for a CSV file
context-loader
Synchronizes startup context across Claude instances, runs at launch.
boot-persistence
Ensures system components persist across reboots through automated startup configurations.
data-processor
Process data with custom algorithms