在编写 github 项目时,有时候会编写各类 README.md
等 markdown 文件,可是 github 默认是没有目录的。java
因而就本身想办法写了一个小工具。git
markdown-toc 能够用来生成 markdown 页面的目录,便于 github 页面展示。github
JDK7+, 请确保 JDK 设置正确。apache
Jar 使用 Maven 进行统一管理。markdown
<dependency> <groupId>com.github.houbb</groupId> <artifactId>markdown-toc</artifactId> <version>1.0.2</version> </dependency>
本项目支持的 md 文件后缀名称为 .md
或者 .markdown
maven
AtxMarkdownToc.newInstance().genTocFile(path);
其中 path 为 md 文件的路径工具
AtxMarkdownToc.newInstance().genTocFile(path);
其中 path 为 md 文件的父类文件夹测试
AtxMarkdownToc.newInstance() .charset("UTF-8") .write(true) .subTree(true);
序号 | 属性 | 默认值 | 说明 |
---|---|---|---|
1 | charset | UTF-8 |
文件编码 |
2 | write | true |
是否将 toc 写入文件(默认写入) |
3 | subTree | true |
是否包含子文件夹的文件(默认包含) |
genTocFile()
返回 TocGen,genTocDir()
返回 List<TocGen>编码
序号 | 属性 | 类型 | 说明 |
---|---|---|---|
1 | filePath | String | 当前 md 的文件路径 |
2 | tocLines | List<String> | 当前 md 文件对应的目录内容 |
单个文件-目录生成测试案例code
markdown-toc