360 Secure SkillHub
360 安全技能中心

Markdown TOC Generator

该 Skill 提供 Python 脚本 generate_toc.py,读取指定 Markdown 文件的标题层级生成目录:默认输出到标准输出,使用 --in-place 时在首个标题后插入 TOC 或替换已有的 toc 标记块,并可用 --max-depth 控制层级、按固定规则生成锚点。

分类:效率
terrycarter1985
terrycarter1985
热度 12.30
最近更新 2026-08-17 03:01:46

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add terrycarter1985/md-toc-generator
兼容性
通用兼容
联网要求
不联网
数据出网
数据不出本机
Metadata
name
md-toc-generator
description
Generate and update table-of-contents (TOC) sections for Markdown files. Use when working with long Markdown documents, READMEs, or technical docs that need a navigable TOC, or when asked to add/update a table of contents in a .md file.

Markdown TOC Generator

Generate a table of contents from the headings in a Markdown file and insert or refresh it.

Quick start

python3 scripts/generate_toc.py <path-to-file.md> [--max-depth 3] [--in-place]
  • Without --in-place: prints the TOC to stdout.
  • With --in-place: inserts the TOC right after the first heading (or updates an existing <!-- toc --> block).

TOC placement

  • If the file contains <!-- toc --> and <!-- /toc --> markers, the block between them is replaced.
  • Otherwise the TOC is inserted immediately after the first # heading.

Anchor rules

  • Lowercase the heading text.
  • Replace spaces with hyphens.
  • Strip punctuation except hyphens and underscores.
  • Duplicate anchors get -1, -2, … suffixes.

Examples

# Print TOC only
python3 scripts/generate_toc.py docs/guide.md

# Insert / refresh TOC in place
python3 scripts/generate_toc.py README.md --in-place --max-depth 4