Skip to content

utility to make sure there is no more than a single top-level heading in the document

License

Notifications You must be signed in to change notification settings

syntax-tree/mdast-normalize-headings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm

mdast-normalize-headings

Build Status Dependency Status

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.

This mdast transformer makes sure that there is only one top-level heading in the document by adjusting headings depths accordingly.

Originally extracted from remark-man.

Example

var normalizeHeadings = require('mdast-normalize-headings');

ast
//=> {
//     "type": "root",
//     "children": [
//       {
//         "type": "heading",
//         "depth": 1,
//         "children": [
//           {
//             "type": "text",
//             "value": "title"
//           }
//         ]
//       },
//       {
//         "type": "heading",
//         "depth": 2,
//         "children": [
//           {
//             "type": "text",
//             "value": "description"
//           }
//         ]
//       },
//       {
//         "type": "heading",
//         "depth": 1,
//         "children": [
//           {
//             "type": "text",
//             "value": "example"
//           }
//         ]
//       }
//     ]
//   }

normalizeHeadings(ast)
//=> {
//     "type": "root",
//     "children": [
//       {
//         "type": "heading",
//         "depth": 1,
//         "children": [
//           {
//             "type": "text",
//             "value": "title"
//           }
//         ]
//       },
//       {
//         "type": "heading",
//         "depth": 3,
//         "children": [
//           {
//             "type": "text",
//             "value": "description"
//           }
//         ]
//       },
//       {
//         "type": "heading",
//         "depth": 2,
//         "children": [
//           {
//             "type": "text",
//             "value": "example"
//           }
//         ]
//       }
//     ]
//   }

API

normalizeHeadings(ast)

Modifies AST in-place. Returns ast.

Related

Install

npm install mdast-normalize-headings

License

MIT

About

utility to make sure there is no more than a single top-level heading in the document

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •