0.0.2 • Published 4 years ago

remark-contents v0.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

remark-contents

remark plugin to extract table of contents.

This plugin extracts only Heading from mdast markdown, then converts them to a nested List keeping the depth.

Install

npm install remark-contents

Usage

var unified = require("unified");
var markdown = require("remark-parse");
var remark2rehype = require("remark-rehype");
var html = require("rehype-stringify");
var contents = require("remark-contents");

var fs = require("fs");
var text = fs.readFileSync("example.md", "utf8");

unified()
  .use(markdown, { commonmark: true })
  .use(contents)
  .use(remark2rehype)
  .use(html)
  .process(text);

This example.md

# Alpha

aaaa

## Bravo

bbbb

### Charlie

cccc

## Delta

dddd

will be converted by this library like...

-   [Alpha](#alpha)

    -   [Bravo](#bravo)

        -   [Charlie](#charlie)

    -   [Delta](#delta)

License

MIT