Socket
Socket
Sign inDemoInstall

mdast-util-toc

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-toc

mdast utility to generate a table of contents from a tree


Version published
Weekly downloads
265K
increased by10.56%
Maintainers
2
Weekly downloads
 
Created

What is mdast-util-toc?

The `mdast-util-toc` package is a utility for generating a Table of Contents (TOC) from Markdown Abstract Syntax Trees (MDAST). It is particularly useful for processing Markdown documents and extracting a structured TOC based on headings.

What are mdast-util-toc's main functionalities?

Generate TOC from MDAST

This feature allows you to generate a Table of Contents from a Markdown Abstract Syntax Tree. The code sample demonstrates how to convert a Markdown string into an MDAST, generate a TOC from it, and then convert the TOC back into a Markdown string.

const { toMarkdown } = require('mdast-util-to-markdown');
const { fromMarkdown } = require('mdast-util-from-markdown');
const { toc } = require('mdast-util-toc');

const markdown = '# Title\n## Subtitle\n### Sub-subtitle';
const tree = fromMarkdown(markdown);
const tocNode = toc(tree);
console.log(toMarkdown(tocNode.map));

Custom Heading Levels

This feature allows you to customize the depth of headings included in the TOC. The code sample demonstrates generating a TOC that includes only headings up to level 2.

const { fromMarkdown } = require('mdast-util-from-markdown');
const { toc } = require('mdast-util-toc');

const markdown = '# Title\n## Subtitle\n### Sub-subtitle';
const tree = fromMarkdown(markdown);
const tocNode = toc(tree, { maxDepth: 2 });
console.log(tocNode.map);

Custom TOC Heading

This feature allows you to specify a custom heading for the TOC. The code sample demonstrates generating a TOC with a custom heading 'Table of Contents'.

const { fromMarkdown } = require('mdast-util-from-markdown');
const { toc } = require('mdast-util-toc');

const markdown = '# Title\n## Subtitle\n### Sub-subtitle';
const tree = fromMarkdown(markdown);
const tocNode = toc(tree, { heading: 'Table of Contents' });
console.log(tocNode.map);

Other packages similar to mdast-util-toc

Keywords

FAQs

Package last updated on 19 Nov 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc