
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@cs-magic/markdown-toc-gen
Advanced tools
A flexible markdown table of contents generator with configurable styles
markdown-toc-gen • 为什么选择 markdown-toc-gen? • 安装 • 快速开始 • 进阶使用 • 配置选项 • 常见问题 • 贡献指南 • License • 致谢
一个强大的 Markdown 目录生成器,基于 markdown-toc 并提供了显著增强,包括完整的中文支持、多种目录样式和丰富的自定义选项。
npm install -g markdown-toc-gen
# 或
yarn global add markdown-toc-gen
# 或
pnpm add -g markdown-toc-gen
<!-- toc -->
<!-- tocstop -->
md-toc README.md
就是这么简单!
# 自动插入目录标记(如果文件中没有)
md-toc README.md --auto-insert
# 使用横向样式(适合简短目录)
md-toc README.md --style horizontal
# 设置最大标题层级
md-toc README.md --max-level 3
# 监听文件变化
md-toc README.md --watch
# 设置日志级别(debug, info, warn, error)
md-toc README.md --log-level debug
# 处理多个文件
md-toc doc1.md doc2.md
# 使用 glob 模式
md-toc "docs/*.md"
创建 .tocrc.json 或 .tocrc.js 文件:
{
"files": ["README.md", "docs/*.md"],
"style": "horizontal",
"autoInsert": true,
"maxLevel": 2,
"watch": false,
"logLevel": "info"
}
import { generateToc } from "markdown-toc-gen";
// 生成目录
await generateToc("README.md", {
style: "horizontal",
autoInsert: true,
maxLevel: 2,
});
// 批量处理
await generateToc(["doc1.md", "doc2.md"], {
style: "vertical",
});
// 使用 glob 模式
await generateToc("docs/*.md", {
watch: true,
});
| 选项 | 说明 | 默认值 | 描述 |
|---|---|---|---|
style | 目录样式 | vertical | horizontal(横向)或 vertical(纵向) |
autoInsert | 自动插入目录标记 | false | 当文件中没有目录标记时自动插入 |
maxLevel | 最大标题层级 | 2 | 控制目录中包含的标题层级 |
watch | 监听文件变化 | false | 当文件变化时自动更新目录 |
logLevel | 日志级别 | info | error/warn/info/debug 控制日志输出 |
markers | 自定义目录标记 | 见下文 | 自定义目录的开始和结束标记 |
默认的目录标记:
<!-- toc -->
目录将在这里生成
<!-- tocstop -->
也支持单行格式:
<!-- toc --><!-- tocstop -->
如果你想在文档中展示目录标记而不让它被处理,需要在标记前添加反斜杠:
\<!-- toc -->
markdown-toc-gen 是基于 markdown-toc 开发的增强版本,主要解决了以下问题:
确保你的标题符合 Markdown 规范,不包含特殊字符。如果仍有问题,可以尝试使用 --log-level debug 查看详细日志。
欢迎提交 Issue 和 Pull Request!在贡献代码前,请先阅读我们的贡献指南。
MIT
FAQs
A flexible markdown table of contents generator with configurable styles
We found that @cs-magic/markdown-toc-gen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.