Nondeterministic Palindrome Machine
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

mdast-normalize-headings

2.0.0 • Public • Published

mdast-normalize-headings

Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to make sure that there is only one top-level heading in the document by adjusting headings depths accordingly.

Providing multiple top-level headings per single markdown document is confusing for tools that assume that there is only a single top-level heading that contains some meta-information (usually title) about the document.

Install

npm:

npm install mdast-normalize-headings

Use

var u = require('unist-builder')
var normalizeHeadings = require('mdast-normalize-headings')
 
var tree = u('root', [
  u('heading', {depth: 1}, [u('text', 'title')]),
  u('heading', {depth: 2}, [u('text', 'description')]),
  u('heading', {depth: 1}, [u('text', 'example')])
])
 
console.log(tree)
 
normalizeHeadings(tree)
 
console.log(tree)

Yields:

{ type: 'root',
  children:
   [ { type: 'heading', depth: 1, children: [Array] },
     { type: 'heading', depth: 2, children: [Array] },
     { type: 'heading', depth: 1, children: [Array] } ] }
{ type: 'root',
  children:
   [ { type: 'heading', depth: 1, children: [Array] },
     { type: 'heading', depth: 3, children: [Array] },
     { type: 'heading', depth: 2, children: [Array] } ] }

API

normalizeHeadings(tree)

Modifies tree in-place. Returns tree.

Security

Use of mdast-normalize-headings does not involve hast so there are no openings for cross-site scripting (XSS) attacks.

Related

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Eugene Sharygin

Install

npm i mdast-normalize-headings

DownloadsWeekly Downloads

27

Version

2.0.0

License

MIT

Unpacked Size

7.31 kB

Total Files

4

Last publish

Collaborators

  • avatar
  • avatar