{"id":19097568,"url":"https://github.com/apocelipes/autotoc","last_synced_at":"2025-04-30T14:44:16.613Z","repository":{"id":57567929,"uuid":"169568446","full_name":"apocelipes/autotoc","owner":"apocelipes","description":"A tool for generating directories for markdown file content","archived":false,"fork":false,"pushed_at":"2025-04-16T07:23:02.000Z","size":164,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-16T09:45:06.943Z","etag":null,"topics":["catalog","gfm","golang","golang-application","markdown","toc","tool"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apocelipes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-02-07T12:29:41.000Z","updated_at":"2025-04-16T07:23:05.000Z","dependencies_parsed_at":"2022-08-28T07:41:03.453Z","dependency_job_id":"194695d7-2212-410c-aef8-3dc48bedd028","html_url":"https://github.com/apocelipes/autotoc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apocelipes%2Fautotoc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apocelipes%2Fautotoc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apocelipes%2Fautotoc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apocelipes%2Fautotoc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apocelipes","download_url":"https://codeload.github.com/apocelipes/autotoc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251723282,"owners_count":21633123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["catalog","gfm","golang","golang-application","markdown","toc","tool"],"created_at":"2024-11-09T03:41:48.305Z","updated_at":"2025-04-30T14:44:16.588Z","avatar_url":"https://github.com/apocelipes.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# autotoc\nautotoc是一个帮助你为markdown文档生成目录的自动化工具。\n\nautotoc遵守gfm格式规范，可用于为支持gfm格式markdown的站点的内容作者为自己的文档生成易于读者阅读和跳转的文档内容目录，将你从繁重的重复劳动中解放出来。\n\n## Installation\n```bash\n# 需要go1.22+，并保证你的$GOPATH/bin在$PATH中\n# go 1.22目前默认会将程序安装至$GOPATH/bin\nexport PATH=$PATH:$GOPATH/bin\ngo install github.com/apocelipes/autotoc@latest\n```\n\n## 快速入门\nautotoc支持从标准输入或文件中读取信息，然后将根据文档内容生成的目录信息输出至标准输出或是写入文件中的`[TOC]`标志的地方。\n\n文档的标题可以是html格式或是markdown格式，autotoc将会自动识别。\n\n如果文件中存在`[TOC]`标志，autotoc将从标志的下一行开始读取文档信息。\n\n你可以通过`--help`或`-h`选项获取帮助信息：\n\n```bash\n$ autotoc --help\n\nUsage: ./autotoc [option]... \u003cfile\u003e\n\n读入file，根据其内容生成目录结构。\n未提供file参数时默认读取stdin。\n\n可选参数：\n-t string, --top-tag string\n        设置作为目录顶层项的tag，将从指定tag开始解析标题 (default: \"h2\")\n-f string, --formatter string\n        选择格式化html代码的方式，目前只支持default和prettyprint(output为markdown时不支持) (default: \"default\")\n--catalog-id string\n        目录的html id(output为markdown时不支持) (default: \"bookmark\")\n--title string\n        目录的标题 (default: \"本文索引\")\n-o string, --output string\n        输出的目录格式，可以为html或md(markdown) (default: \"html\")\n-l string, --title-language string\n        扫描文件的标题语法类型，可以为html，md或multi（multi同时支持所有type） (default: \"multi\")\n-i string, --indent string\n        目录的缩进，默认为2空格，输入\\t以替代tab (default: 2空格)\n-m string, --toc-mark string\n        指定文件中写入目录的位置 (default: \"[TOC]\")\n--exclude-title=[title1,title2]\n        过滤掉内容等于参数指定值的标题 (default: \"参考\")\n--exclude-filter=[pattern]\n        过滤掉内容和参数指定的表达式匹配的标题 (default: \"\")\n-w      是否将目录写入文件指定位置\n--full  是否将目录和文章信息组合后一同输出\n--no-exclude    不过滤任何标题\n-h, --help      显示本帮助信息并终止程序\n```\n\n假设我们有一个名为`example.md`的文件，它的内容如下：\n```markdown\n[TOC]\n# 主标题\n\n主标题的描述\n\n## 一级次标题1\n\n一级次标题1的描述\n\n### 二级次标题1\n\n二级次标题1的描述\n\n### 二级次标题2\n\n二级次标题2的描述\n\n## 一级次标题2\n\n一级次标题2的描述\n```\n\n输出HTML形式的并格式化的目录：\n```bash\n$ autotoc -t h1 example.md\n\n\u003cblockquote id=\"bookmark\"\u003e\n  \u003ch4\u003e本文索引\u003c/h4\u003e\n  \u003cul\u003e\n    \u003cli\u003e\n      \u003ca href=\"#主标题\"\u003e主标题\u003c/a\u003e\n      \u003cul\u003e\n        \u003cli\u003e\n          \u003ca href=\"#一级次标题1\"\u003e一级次标题1\u003c/a\u003e\n          \u003cul\u003e\n            \u003cli\u003e\u003ca href=\"#二级次标题1\"\u003e二级次标题1\u003c/a\u003e\u003c/li\u003e\n            \u003cli\u003e\u003ca href=\"#二级次标题2\"\u003e二级次标题2\u003c/a\u003e\u003c/li\u003e\n          \u003c/ul\u003e\n        \u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#一级次标题2\"\u003e一级次标题2\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/li\u003e\n  \u003c/ul\u003e\n\u003c/blockquote\u003e\n```\n\n输出markdown格式的目录：\n```bash\n$ autotoc -t h1 -o md example.md\n\n#### 本文索引:\n- [主标题](#主标题)\n  - [一级次标题1](#一级次标题1)\n    - [二级次标题1](#二级次标题1)\n    - [二级次标题2](#二级次标题2)\n  - [一级次标题2](#一级次标题2)\n```\n\nautotoc能够从标准输入读取信息，因此可以在管道中组合使用它：\n```bash\n$ cat example.md | autotoc -t h1 -o md\n\n#### 本文索引:\n- [主标题](#主标题)\n  - [一级次标题1](#一级次标题1)\n    - [二级次标题1](#二级次标题1)\n    - [二级次标题2](#二级次标题2)\n  - [一级次标题2](#一级次标题2)\n```\n\n使用`-w`参数可以让目录信息写入到文件中写有`[TOC]`标志的地方：\n```bash\n$ autotoc -t h1 -o md -w example.md\n$ head -n 10 example.md\n\n#### 本文索引:\n- [主标题](#主标题)\n  - [一级次标题1](#一级次标题1)\n    - [二级次标题1](#二级次标题1)\n    - [二级次标题2](#二级次标题2)\n  - [一级次标题2](#一级次标题2)\n\n# 主标题\n\n主标题的描述\n```\n\n注意，autotoc在生成目录到章节对应的链接时会将除了unicode字母和数字之外的其他字符去除。这一做法在不支持gfm格式或是对gfm兼容性较弱的地方可能导致目录无法跳转或其他问题。\n\n## TODO\n- [ ] 支持完整的gfm语法\n- [ ] 补充parser的单元测试\n- [ ] 自定义包裹目录信息的模板\n- [ ] 添加verbose模式\n- [ ] 简化exclude dir处理逻辑\n\n欢迎提交issue或PR！\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapocelipes%2Fautotoc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapocelipes%2Fautotoc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapocelipes%2Fautotoc/lists"}