ToC generator for markdown.
If links in this document not avaiable, please access README on GitHub directly.
Analyse markdown text and generate Table of Contents.
-
API mode
const toc = require('@toc/markdown'); toc(markdownText); // Return markdown text containing a "Table of Contents" section.
-
CLI mode
# Install globally. # Command `toc-md` will be created. npm install -g @toc/markdown # Read markdown file and write markdown text with "Table of Contents" # section into another file. toc-md /path/of/input.md /path/of/output.md
- void toc( string markdownText [, Object options ])
options may contain following properties:
-
options.indent number | string DEFAULT "\u0009"
Indent used on creating sub list in the ToC catalog. The default value is a TABSTOP character. -
options.ignore string | string[] DEFAULT "< position"
Indicate what titles should be ignored.
The possible values may be:// Titles of sections preceding ToC section will be ingored. { ignore: '< position' } // Titles of sections following ToC section will be ingored. { ignore: '> position' } // Title of section No.3 will be ignored. { ignore: 3 } // Title of section No.1, No.2, No.9 and the following will be ignored. { ignore: [ 1, 2, '> 9' ] }
-
options.position number DEFAULT 1
Indicate where to put the generated ToC section.
-1 means to put ToC at first (before the headline), while 0 to put ToC just after the headline.
If the value is larger than 0, ToC will be put just before the n-th second leve title line. -
options.title string DEFAULT "Table of Contents"
If set falsy, generated ToC will be bare without section title. -
options.overwrite boolean DEFAULT true
Whether to overwrite existing ToC section (a second level section with the same title equals to options.title).