Socket
Book a DemoInstallSign in
Socket

remark-extract-toc

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-extract-toc

remark plugin to store table of contents

Source
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

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 = require("unified");
var markdown = require("remark-parse");
var toc = require("remark-extract-toc");

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

var processor = unified()
  .use(markdown, { commonmark: true })
  .use(toc);

var node = processor.parse(text);
var tree = processor.runSync(node);
console.log(tree);

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

KeyDefaultTypeDescription
keys[]string[]Add extra field to tree object. For example, use remark-slug to add id and set { keys: ["data"] }.

License

MIT

Keywords

unist

FAQs

Package last updated on 24 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts