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.
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"
// }
// ]
// }
// ]
// }
Modifies AST in-place. Returns ast
.
- remark-normalize-headings — remark plugin wrapper.
npm install mdast-normalize-headings
MIT