remark-normalize-headings
remark plugin to make sure that there is only one top-level heading in a document by adjusting heading 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.
Note!
This plugin is ready for the new parser in remark (remarkjs/remark#536
). No change is needed: it works exactly the same now as it did before!
Install
npm:
npm install remark-normalize-headings
Use
Say we have the following file, example.md
:
# Title
# Description
## Usage
### Example
## API
# Related
And our script, example.js
, looks as follows:
var vfile = require('to-vfile')
var remark = require('remark')
var normalizeHeadings = require('remark-normalize-headings')
remark()
.use(normalizeHeadings)
.process(vfile.readSync('example.md'), function(err, file) {
if (err) throw err
console.log(String(file))
})
Now, running node example
yields:
# Title
## Description
### Usage
#### Example
### API
## Related
API
remark().use(normalizeHeadings)
Make sure that there is only one top-level heading in a document by adjusting heading depths accordingly.
Security
Use of remark-normalize-headings
does not involve rehype (hast) or user content so there are no openings for cross-site scripting (XSS) attacks.
Related
mdast-normalize-headings
— mdast utility that is in the core of this plugin
Contribute
See contributing.md
in remarkjs/.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