# mdast-normalize-headings

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

Latest version **4.0.0** (published 2023-07-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install mdast-normalize-headings
pnpm add mdast-normalize-headings
yarn add mdast-normalize-headings
bun add mdast-normalize-headings
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2023-07-07 |
| First published | 2015-07-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Eugene Sharygin |
| Maintainers | wooorm, kmck |
| Keywords | unist, mdast, mdast-util, util, utility, tree, header, heading, depth, title, count, level |

## Links

- npm: https://www.npmjs.com/package/mdast-normalize-headings
- Repository: https://github.com/syntax-tree/mdast-normalize-headings
- Homepage: https://github.com/syntax-tree/mdast-normalize-headings#readme
- Issues: https://github.com/syntax-tree/mdast-normalize-headings/issues
- Funding: https://opencollective.com/unified
- npm.io page: https://npm.io/package/mdast-normalize-headings

## Dependencies (2)

- [@types/mdast](https://npm.io/package/@types/mdast.md) ^4.0.0
- [unist-util-visit](https://npm.io/package/unist-util-visit.md) ^5.0.0

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 4.0.0 (latest) — 2023-07-07
- 3.1.1 — 2023-01-25
- 3.1.0 — 2021-07-30
- 3.0.0 — 2021-04-23
- 2.0.0 — 2020-02-22
- 1.0.2 — 2019-05-24
- 1.0.1 — 2018-08-20
- 1.0.0 — 2017-06-13
- 0.3.0 — 2016-01-04
- 0.2.0 — 2015-07-30
- 0.1.0 — 2015-07-15

## README

# mdast-normalize-headings

[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]

[mdast][] utility to normalize heading depths.

## Contents

*   [What is this?](#what-is-this)
*   [When should I use this?](#when-should-i-use-this)
*   [Install](#install)
*   [Use](#use)
*   [API](#api)
    *   [`normalizeHeadings(tree)`](#normalizeheadingstree)
*   [Types](#types)
*   [Compatibility](#compatibility)
*   [Security](#security)
*   [Related](#related)
*   [Contribute](#contribute)
*   [License](#license)

## What is this?

This package is a utility that normalizes the heading structure of documents.
It makes sure one top-level heading is used by adjusting headings depths
accordingly.

## When should I use this?

This utility can be useful when working with tools that assume that there is a
single top-level heading that contains some meta-information (usually a title)
about the document.

A plugin, [`remark-normalize-headings`][remark-normalize-headings], exists that
does the same but for [remark][].

## Install

This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:

```sh
npm install mdast-util-normalize-headings
```

In Deno with [`esm.sh`][esmsh]:

```js
import {normalizeHeadings} from 'https://esm.sh/mdast-util-normalize-headings@4'
```

In browsers with [`esm.sh`][esmsh]:

```html
<script type="module">
  import {normalizeHeadings} from 'https://esm.sh/mdast-util-normalize-headings@4?bundle'
</script>
```

## Use

```js
import {normalizeHeadings} from 'mdast-normalize-headings'
import {u} from 'unist-builder'

const tree = u('root', [
  u('heading', {depth: 1}, [u('text', 'title')]),
  u('heading', {depth: 2}, [u('text', 'description')]),
  u('heading', {depth: 1}, [u('text', 'example')])
])

normalizeHeadings(tree)

console.log(tree)
```

Yields:

```js
{
  type: 'root',
  children: [
    {type: 'heading', depth: 1, children: [Array]},
    {type: 'heading', depth: 3, children: [Array]},
    {type: 'heading', depth: 2, children: [Array]}
  ]
}
```

## API

This package exports the identifier
[`normalizeHeadings`][api-normalizeheadings].
There is no default export.

### `normalizeHeadings(tree)`

Make sure that there is only one top-level heading in the document by adjusting
headings depths accordingly.

###### Parameters

*   `tree` ([`Node`][node])
    — tree to change

###### Returns

Nothing (`undefined`).

## Types

This package is fully typed with [TypeScript][].
It exports no additional types.

## Compatibility

Projects maintained by the unified collective are compatible with maintained
versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`mdast-normalize-headings@^4`, compatible with Node.js 16.

## Security

Use of `mdast-normalize-headings` does not involve **[hast][]** so there are no
openings for [cross-site scripting (XSS)][xss] attacks.

## Related

*   [`remark-normalize-headings`][remark-normalize-headings]
    — remark plugin

## Contribute

See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
ways to get started.
See [`support.md`][support] for ways to get help.

This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.

## License

[MIT][license] © Eugene Sharygin

<!-- Definitions -->

[build-badge]: https://github.com/syntax-tree/mdast-normalize-headings/workflows/main/badge.svg

[build]: https://github.com/syntax-tree/mdast-normalize-headings/actions

[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-normalize-headings.svg

[coverage]: https://codecov.io/github/syntax-tree/mdast-normalize-headings

[downloads-badge]: https://img.shields.io/npm/dm/mdast-normalize-headings.svg

[downloads]: https://www.npmjs.com/package/mdast-normalize-headings

[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-normalize-headings

[size]: https://bundlejs.com/?q=mdast-normalize-headings

[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[backers-badge]: https://opencollective.com/unified/backers/badge.svg

[collective]: https://opencollective.com/unified

[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg

[chat]: https://github.com/syntax-tree/unist/discussions

[npm]: https://docs.npmjs.com/cli/install

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

[esmsh]: https://esm.sh

[typescript]: https://www.typescriptlang.org

[license]: license

[health]: https://github.com/syntax-tree/.github

[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md

[support]: https://github.com/syntax-tree/.github/blob/main/support.md

[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md

[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting

[hast]: https://github.com/syntax-tree/hast

[mdast]: https://github.com/syntax-tree/mdast

[node]: https://github.com/syntax-tree/mdast#node

[remark]: https://github.com/remarkjs/remark

[remark-normalize-headings]: https://github.com/remarkjs/remark-normalize-headings

[api-normalizeheadings]: #normalizeheadingstree

---
_Source: https://npm.io/package/mdast-normalize-headings · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
