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-indexer
试用Scan a directory of Markdown files, extract titles/headings/frontmatter, build a searchable index JSON, and output a concise summary report. Use when you need to inventory, catalog, or make a folder of .md files discoverable without reading each file individually.
它能做什么
Scan a directory of Markdown files, extract titles/headings/frontmatter, build a searchable index JSON, and output a concise summary report. Use when you need to inventory, catalog, or make a folder of .md files discoverable without reading each file individually.
技能文档
Markdown Indexer
Scan Markdown files in a directory and produce a structured index.
When to use it
- You have a folder of
.mdfiles (notes, docs, wikis) and need to know what's in them at a glance. - Before uploading or publishing a collection of documents, you want a catalog.
- You need a JSON index for downstream search or automation.
Prerequisites
jqis installed (used for JSON formatting)- Files must be UTF-8 encoded Markdown
Usage
Step 1: Scan a directory
# Basic scan — outputs index.json in current directory
find ./docs -name "*.md" -print0 | while IFS= read -r -d '' f; do
title=$(grep -m1 '^# ' "$f" | sed 's/^# //' | tr '\n' ' ')
[ -z "$title" ] && title=$(basename "$f" .md)
headings=$(grep -c '^#' "$f" 2>/dev/null || echo 0)
lines=$(wc -l < "$f")
frontmatter=$(head -20 "$f" | grep -c '^---$' || echo 0)
echo "{\"file\":\"$f\",\"title\":\"$title\",\"headings_count\":$headings,\"lines\":$lines,\"has_frontmatter\":$frontmatter}"
done | jq -s '.' > index.json
Step 2: View summary
jq 'length' index.json # total files
jq 'sort_by(-.lines)[:5]' index.json # top 5 longest
jq '[.[] | select(.has_frontmatter >= 2)] | length' index.json # files with YAML frontmatter
Step 3: Generate a Markdown report
jq -r '.[] | "- **\(.title)** — `\(.file)` (\(.lines) lines, \(.headings_count) headings)"' index.md > catalog.md
Output
index.json: Array of objects withfile,title,headings_count,lines,has_frontmattercatalog.md(optional): Human-readable Markdown table of contents
Example: Pipeline with other tools
# 1. Index the docs folder
bash scan.sh ./docs
# 2. Filter out files without headings
jq '[.[] | select(.headings_count > 0)]' index.json > valid-index.json
# 3. Upload to your knowledge base
curl -X POST https://api.example.com/import -d @valid-index.json
相关技能
Generate a Table of Contents (TOC) from Markdown headings. Supports heading extraction, multiple output formats, and configurable level filtering.
Scan markdown files and verify that all hyperlinks (both local files and remote URLs) resolve correctly. Use when you need to: (1) verify documentation before publishing, (2) check a repo README or wiki links, (3) audit markdown files for broken links before generating static sites or releasing content, (4) validate links in collected digital assets before archiving.
Generate a table of contents (TOC) for any Markdown file by extracting its ATX headings (# ..
Format and lint markdown files for consistency and readability. Use when Codex needs to normalize markdown documents, fix heading levels, standardize link fo...
让 Markdown 在 GitHub、MDX、Pandoc、文档站、Slack、Notion 等解析器中正确渲染,并定位修复具体损坏位置。