remark-extract-toc
remark plugin to store table of contents.
This plugin extracts only Heading
from mdast markdown, then converts them to a nested object tree keeping the depth.
Install
npm install remark-extract-toc
Usage
var unified = ;var markdown = ;var extractToc = ; var fs = ;var text = fs; var processor = ; var node = processor;var tree = processor;console;
This example.md
# Alpha
aaaa
## Bravo
bbbb
### Charlie
cccc
## Delta
dddd
will be converted by this library like...
[
{
depth: 1,
value: "Alpha",
children: [
{
depth: 2,
value: "Bravo",
children: [{ depth: 3, value: "Charlie", children: [] }],
},
{
depth: 2,
value: "Delta",
children: [],
},
],
},
]
API
remark().use(toc[, options])
Options
Key | Default | Type | Description |
---|---|---|---|
flatten | false | boolean | If true, toc is extracted as a list not nested. |
keys | [] | string[] | Add extra field to tree object. For example, use remark-slug to add id and set { keys: ["data"] } . |
License
MIT