@toc/markdown
v0.0.4
Published
ToC generator for markdown.
Downloads
55
Readme
@toc/markdown
ToC generator for markdown.
If links in this document not avaiable, please access README on GitHub directly.
Description
Analyse markdown text and generate Table of Contents.
Table of Contents
Get & Started
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
API
- 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).