Generate a HTML table of contents using cheerio.
npm install html-toc> Generate a HTML table of contents using cheerio.
Install with npm:
``sh`
$ npm install --save html-toc
`js`
var toc = require('html-toc');
console.log(toc(htmlString[, options]));
Type: string
Default: #toc (usage:
)Specify the id for where the table of contents should be injected.
Example
`js
toc(str, {id: '#navigation'});
`Usage:
`html
`$3
Type:
booleanDefault:
undefinedSet to
false to disable anchors.Example
`js
toc(str, {anchors: false});
`$3
Customize the template for creating anchors.
Type:
functionDefault
`html
`Example
`js
toc(str, {
anchorTemplate: function(id) {
return ;
}
});
`$3
Heading selectors to use for generating the table of contents.
Type:
stringDefault:
h1,h2Example
Generate a table of contents for all headings h1-h4.
`js
toc(str, {selectors: 'h1,h2,h3,h4'});
`$3
Set whether to generate
id attribute based on parent headingType:
booleanDefault:
trueExample
`js
toc(str, {parentLink: false});
`$3
Customize the slugger for generating
id attribute.Type:
functionDefault: markdown-slug
Example
`js
toc(str, {
slugger: function(text) {
const re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^{|}~]/g;$3
Specify html to be injected before table of contents.
Type:
stringDefault:
''Example
`js
toc(str, {header: 'Contents
'});
`$3
Set minimum number of headings for injecting table of contents.
Type:
numberDefault:
0Example
`js
toc(str, {minLength: 2});
`$3
Type:
booleanDefault:
falseSet to
true to add id attribute to selected headings even when headings' number is smaller than options.minLength.Example
Always add
id attribute.`js
toc(str, {addID: true});
`About
$3
* breakdance: Breakdance is a node.js library for converting HTML to markdown. Highly pluggable, flexible and easy… more | homepage
* markdown-toc: Generate a markdown TOC (table of contents) with Remarkable. | homepage with Remarkable.")
* remarkable: Markdown parser, done right. 100% Commonmark support, extensions, syntax plugins, high speed - all in… more | homepage
$3
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
$3
| Commits | Contributor |
| --- | --- |
| 9 | dgeibi |
| 2 | jonschlinkert |
$3
_(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)_
To generate the readme, run the following command:
`sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
`$3
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
`sh
$ npm install && npm test
``Jon Schlinkert
* github/jonschlinkert
* twitter/jonschlinkert
Copyright © 2017, Jon Schlinkert.
Released under the MIT License.
*
_This file was generated by verb-generate-readme, v0.6.0, on May 14, 2017._