rehype-shift-heading

rehype plugin to change the rank (depth, level) of headings

Usage no npm install needed!

<script type="module">
  import rehypeShiftHeading from 'https://cdn.skypack.dev/rehype-shift-heading';
</script>

README

rehype-shift-heading

Build Coverage Downloads Size Sponsors Backers Chat

rehype plugin to change the rank (depth, level) of headings.

Contents

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install rehype-shift-heading

Use

Say example.js looks as follows:

import {rehype} from 'rehype'
import rehypeShiftHeading from 'rehype-shift-heading'

rehype()
  .data('settings', {fragment: true})
  .use(rehypeShiftHeading, {shift: 1})
  .process('<h1>Alpha!</h1>')
  .then((file) => {
    console.log(String(file))
  })

Now, running node example yields:

<h2>Alpha!</h2>

API

This package exports no identifiers. The default export is rehypeShiftHeading.

unified().use(rehypeShiftHeading, options)

rehype plugin to change the rank (depth, level) of headings. Does not shift past h1 and h6.

options.shift

Number to shift headings (number, required). Can be negative to decrease heading levels.

Security

Use of rehype-shift-heading is safe.

Related

Contribute

See contributing.md in rehypejs/.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 © Titus Wormer