360 Secure SkillHub
360 安全技能中心

markdown-toc

该 Skill 提供纯 Python 标准库实现的命令行脚本,读取 Markdown 文件并提取全部 H1-H6 标题,按层级输出缩进的目录列表,支持 --ol 有序列表、--min 指定起始层级、--flat 扁平列表、--anchor 内联锚点链接;标题文本按规则转为锚点,仅输出目录文本供粘贴回文档。

fuzzyb33s
fuzzyb33s
热度 33.96
最近更新 2026-06-24 06:38:47
分类:效率依赖:代码执行 / 读写文件应用场景:文件转换 / 自动化脚本

安装技能

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

执行命令安装此 skill: npx secure-skills-cli add fuzzyb33s/markdown-toc
Metadata
name
markdown-toc
description
Generate a Table of Contents from Markdown headings. Pure Python stdlib, no deps.

markdown-toc — Generate Table of Contents from Markdown

What It Does

Reads a Markdown file, extracts all headings (H1-H6), and outputs a clickable TOC string you can paste back into the document.

Usage

python scripts/generate_toc.py <file.md>
python scripts/generate_toc.py <file.md> --ol       # ordered list (1. 2. 3.)
python scripts/generate_toc.py <file.md> --min 2    # start from H2 (skip H1)
python scripts/generate_toc.py <file.md> --flat     # no indentation, flat bullet list

Options

Flag Description
--ol Ordered list (1. 2. 3.) instead of bullets
--min N Skip headings below level N (default: 1)
--flat No indentation — flat list regardless of depth
--anchor Show anchor links inline: - [Section](#section)

Output Format

  • Default: indented bullet list matching heading depth
  • --ol: same structure but numbered
  • --min N: skip H1 (or lower based on N)
  • Heading text slugified to anchor: ## My Awesome Section -> #my-awesome-section

Anchor Slug Rules

  • Lowercase
  • Spaces/colons -> hyphens
  • Stripped: !?.,'()[]{} and special chars
  • Chinese/Japanese/Korean/accents: stripped to ASCII equivalent where possible
  • Collapses multiple hyphens

Examples

Input (sample.md):

# Introduction
## Background
### History
## Installation

Output:

- [Introduction](#introduction)
  - [Background](#background)
    - [History](#history)
  - [Installation](#installation)

With --ol --min 2:

1. [Background](#background)
     1. [History](#history)
2. [Installation](#installation)

Files

  • SKILL.md — this file
  • scripts/generate_toc.py — main CLI script