unified

Project: remarkjs/remark-normalize-headings

Package: remark-normalize-headings@2.0.0

  1. Dependencies: 1·Dependents: 9
  2. remark plugin to make sure there is no more than a single top-level heading in a document
  1. remark 192
  2. unified 152
  3. plugin 133
  4. markdown 122
  5. mdast 77
  6. remark-plugin 73
  7. heading 26
  8. depth 5
  9. level 5
  10. count 3
  11. header 2
  12. title 2

remark-normalize-headings

Build Coverage Downloads Size Sponsors Backers Chat

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.

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.

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