将目录添加到标记文件

mdtoc的Python项目详细描述


标记目录生成器

mdtoc是一个命令行实用程序,用于在Markdown(.md)文件中生成目录

SupportsPython 2.7 | 3.4 | 3.5 | 3.6 | 3.7
Latest Releaselatest release
Package Statusstatus
Licenselicense

安装

通过pip install mdtoc安装。

基本用法

将这些分隔符添加到标记文件中:

<!---toc start-->
<!---toc end-->

然后,从命令行运行:

$ mdtoc /path/to/myfile.md

这将覆盖目标文件/path/to/myfile.md的位置,用目录替换上面标记的分隔符之间的文本。(呈现时分隔符本身是不可见的注释。)如果要写入新文件,请使用--outfile。如果只想将toc写入stdout,请使用--stdout

技术细节

mdtoc只解析标记为“atx样式”的头:在行的开头,后跟头的1-6个哈希字符(#)。它不会not当前检测到“setext style”(带下划线)头。

<^ >Daring Fireball page是最早存在于标记的初始规范语法规范中的东西。(这个页面是由john gruber创建和托管的,johngruber是markdown作为一种语言的最初开发人员)但是,这个页面留下了大量的歧义。正因为如此,mdtoc还合并了来自GitHub-flavored Markdown的规则,从而提供了更完整的规范:

An ATX heading consists of a string of characters, parsed as inline content, between an opening sequence of 1–6 unescaped # characters and an optional closing sequence of any number of unescaped # characters. The opening sequence of # characters must be followed by a space or by the end of line. The optional closing sequence of #s must be preceded by a space and may be followed by spaces only. The opening # character may be indented 0-3 spaces. The raw contents of the heading are stripped of leading and trailing spaces before being parsed as inline content. The heading level is equal to the number of # characters in the opening sequence.

请将GitHub-flavored Markdown规则视为此工具使用的最终经验规则集。如果发现有违反此规则的情况,欢迎使用拉取请求。

您还可以查看tests/examples.md中的实例这个文档是GitHub采用降价格式的直观证明,还包括一些甚至GitHub页面本身都没有涉及的新颖示例

GitHub的一个突破是,这个工具将制表符作为空格进行计数,无论是出于何种目的这与github规范不同,github规范将空间严格定义为U+0020

另外两个小音符:

  • mdtoc将忽略标记代码块(```)中以#开头的注释。
  • mdtoc不检查头级别的一致性/连续性。如果3级标题直接位于1级标题之后,则会按原样呈现。

完整的命令行帮助文档

$ mdtoc --help
usage: mdtoc [-h] [--version] [--check-links] [--outfile OUTFILE | --stdout]
             markdown_file

Generates table of contents for Markdown files.

The algorithm searches for the text blocks
between the delimiters:

<!---toc start--->
... anything ...
<!---toc end--->

The contents of the block are then replaced
by a table of contents.

positional arguments:
  markdown_file      relative or abs. path of the Markdown
                     (.md) file to overwrite

optional arguments:
  -h, --help         show this help message and exit
  --version          show program's version number and exit
  --check-links      find all hyperlinks and ensure that
                     they point to something valid
  --outfile OUTFILE  instead of overwriting the input file,
                     write to this file instead
  --stdout           don't write or overwrite any file;
                     just print the TOC to stdout

Created by Scott Frazer (https://github.com/scottfrazer).

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
相对于框架java窗口的鼠标位置错误   Java 8流peek api   java将数据附加到文件中   java使用ExoPlayer 2.8播放播放列表中的特定文件   JavaSpring国际化:如何动态设置语言环境值   java如何在mysql中实现两个表之间的两个关联   java在gradle可执行jar文件中包含运行时参数   surefire插件中的java maven多套测试套件   java试图理解堆分析以确定内存泄漏或所需的大量内存   java识别字符串有数字   数组如何解决错误“java.lang.ArrayIndexOutOfBoundsException:5”   java Swt文件对话框选择的文件太多?   java此登录代码易受SQL注入攻击吗?   Java[3]中的文件<identifier>预期编译错误   java如何在spring webflux中发送列表   jar中未找到java文件异常   如何在java中合并2D数组?   java如何评测本机JNI库