0.5.0 • Published 9 years ago
doctoc-generator v0.5.0
DocToc-generator
README.md toc generator, a fork from DocToc
Installation
npm install doctoc-generator
Usage
Example:
test.md
:
# Test
## title1
content here
### sub-title
sub content here
```
## test1
### test2
wow
```
## title2
content here
### sub-title
sub content here
code:
var doctoc = require("doctoc-generator");
var fs = require("fs");
var file = fs.readFileSync("./test.md", {encoding: 'utf8'});
doctoc(file, 4, 'github.com', function(toc) {
console.log(toc);
})
Result:
{ content:
[ { rank: 1,
name: 'Test',
line: 0,
content: '',
instance: 0,
anchor: '[Test](#test)',
rawAnchor: 'test' },
{ rank: 2,
name: 'title1',
line: 2,
content: 'content here\n',
instance: 0,
anchor: '[title1](#title1)',
rawAnchor: 'title1' },
{ rank: 3,
name: 'sub-title',
line: 5,
content: 'sub content here\n\n```\n## test1\n\n### test2\n\nwow\n```\n',
instance: 0,
anchor: '[sub-title](#sub-title)',
rawAnchor: 'sub-title' },
{ rank: 2,
name: 'title2',
line: 16,
content: 'content here\n',
instance: 0,
anchor: '[title2](#title2)',
rawAnchor: 'title2' },
{ rank: 3,
name: 'sub-title',
line: 19,
content: 'sub content here',
instance: 1,
anchor: '[sub-title](#sub-title-1)',
rawAnchor: 'sub-title-1' } ],
toc: '- [Test](#test)\n - [title1](#title1)\n - [sub-title](#sub-title)\n - [title2](#title2)\n - [sub-title](#sub-title-1)\n' }
Arguments
doctoc(<markdown string>, <max header>, 'github.com', function(toc) {
// callback
})
- Markdown string
- Max header Number
- github mode or bitbucket mode (options: 'github.com' or 'bitbucket.org')
- Callback function, with param TOC value.
License
MIT