Linkify HTML headers and generate a TOC.
npm install tocLinkify HTML headers and generate a TOC.
npm install toc``js`
var toc = require('toc');
`js`
var stripped = toc.untag(html);
`js`
var anchor = toc.anchor(arbitraryText);
`js`
var names = {};
var guaranteedUniqueAnchor1 = toc.unique(names, toc.anchor(arbitraryText));
var guaranteedUniqueAnchor2 = toc.unique(names, toc.anchor(arbitraryText));
`js`
var htmlWithAnchorsAndTOC = toc.process(html [, options]);
#### options
placeholder - RegExp - Used to match TOC placeholder. Defaults to //gi.toc.anchorize
* _Because this method calls the and toc.toc methods internally, their options may be specified as well._
`js`
var obj = toc.anchorize(html [, options]);
#### options
headers - RegExp - Used to match HTML headers. Defaults to /.Number
* tocMin - - Min header level to add to TOC. Defaults to 2.Number
* tocMax - - Max header level to add to TOC. Defaults to 6.Number
* anchorMin - - Min header level to anchorize. Defaults to 2.Number
* anchorMax - - Max header level to anchorize. Defaults to 6.String
* header - | Function - Lodash template string or function used to anchorize a header.
`js`
var obj = toc.toc(headers [, options]);
#### options
* openUL - String | Function - Lodash template string or function used to generate the TOC.String
* closeUL - | Function - Lodash template string or function used to generate the TOC.String
* openLI - | Function - Lodash template string or function used to generate the TOC.String
* closeLI - | Function - Lodash template string or function used to generate the TOC.String
* TOC - | Function - Lodash template string or function used to wrap the generated TOC.
The default HTML is pretty awesome, but you can customize the hell out of the generated HTML, eg.
`js`
var processedHTML = toc.process(unprocessedHTML, {
header: '
TOC: '<%= toc %>',
openUL: '',
',
closeUL: '
openLI: '
closeLI: '
});
method internals into .anchorize and .toc methods. Renamed toc template option to TOC`.