360 Secure SkillHub
360 安全技能中心

Markdown TOC Generator

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

terrycarter1985
terrycarter1985
热度 16.61
最近更新 2026-08-17 03:01:46
分类:效率依赖:代码执行 / 读写文件应用场景:文件转换 / 自动化脚本

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add 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