<commit_before>[![npm](https://nodei.co/npm/mdast-normalize-headings.png)](https://npmjs.com/package/mdast-normalize-headings)

# mdast-normalize-headings

[![Build Status][travis-badge]][travis] [![Dependency Status][david-badge]][david]

> :warning:
>
> This is an AST transformer for [mdast][] syntax trees. A [remark][] plugin has been split off into [a different project][remark-normalize-headings][].

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][].

[mdast]: https://github.com/syntax-tree/mdast
[remark]: https://github.com/wooorm/remark
[remark-man]: https://github.com/wooorm/remark-man
[remark-normalize-headings]: https://github.com/eush77/remark-normalize-headings

[travis]: https://travis-ci.org/eush77/mdast-normalize-headings
[travis-badge]: https://travis-ci.org/eush77/mdast-normalize-headings.svg
[david]: https://david-dm.org/eush77/mdast-normalize-headings
[david-badge]: https://david-dm.org/eush77/mdast-normalize-headings.png

## Example

```js
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"
//           }
//         ]
//       }
//     ]
//   }
```

## API

#### `normalizeHeadings(ast)`

Modifies AST in-place. Returns `ast`.

## Related

-   [remark-normalize-headings][] — [remark][] plugin wrapper.

## Install

```
npm install mdast-normalize-headings
```

## License

MIT
<commit_msg>Remove warning<commit_after>[![npm](https://nodei.co/npm/mdast-normalize-headings.png)](https://npmjs.com/package/mdast-normalize-headings)

# mdast-normalize-headings

[![Build Status][travis-badge]][travis] [![Dependency Status][david-badge]][david]

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][].

[mdast]: https://github.com/syntax-tree/mdast
[remark]: https://github.com/wooorm/remark
[remark-man]: https://github.com/wooorm/remark-man
[remark-normalize-headings]: https://github.com/eush77/remark-normalize-headings

[travis]: https://travis-ci.org/eush77/mdast-normalize-headings
[travis-badge]: https://travis-ci.org/eush77/mdast-normalize-headings.svg
[david]: https://david-dm.org/eush77/mdast-normalize-headings
[david-badge]: https://david-dm.org/eush77/mdast-normalize-headings.png

## Example

```js
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"
//           }
//         ]
//       }
//     ]
//   }
```

## API

#### `normalizeHeadings(ast)`

Modifies AST in-place. Returns `ast`.

## Related

-   [remark-normalize-headings][] — [remark][] plugin wrapper.

## Install

```
npm install mdast-normalize-headings
```

## License

MIT

{'fraction_non_alphanumeric': 0.19919041996964074, 'fraction_numerical': 0.0053972002023950074, 'mean_word_length': 1.639074321317312, 'pattern_counts': {'":': 68, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 20, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1929679', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1904, 'n_words': 348}