# @mdit-vue/plugin-headers

> A markdown-it plugin to get markdown headers

Latest version **3.0.2** (published 2025-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mdit-vue/plugin-headers
pnpm add @mdit-vue/plugin-headers
yarn add @mdit-vue/plugin-headers
bun add @mdit-vue/plugin-headers
```

## Health

**Score 50/100 (C)** — status: stable.

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

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2025-08-11 |
| First published | 2022-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20.0.0 |
| Dependencies | 4 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 221 |
| Author | meteorlxy |
| Maintainers | meteorlxy |
| Keywords | markdown-it, markdown-it-plugin, vue, header, heading |

## Links

- npm: https://www.npmjs.com/package/@mdit-vue/plugin-headers
- Repository: https://github.com/mdit-vue/mdit-vue
- Homepage: https://github.com/mdit-vue
- Issues: https://github.com/mdit-vue/mdit-vue/issues
- npm.io page: https://npm.io/package/@mdit-vue/plugin-headers

## Dependencies (4)

- [markdown-it](https://npm.io/package/markdown-it.md) ^14.1.0
- [@mdit-vue/types](https://npm.io/package/@mdit-vue/types.md) 3.0.2
- [@mdit-vue/shared](https://npm.io/package/@mdit-vue/shared.md) 3.0.2
- [@types/markdown-it](https://npm.io/package/@types/markdown-it.md) ^14.1.2

## 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

- 3.0.2 (latest) — 2025-08-11
- 3.0.1 — 2025-08-11
- 3.0.0 — 2025-08-11
- 2.1.4 — 2025-04-10
- 2.1.3 — 2024-05-13
- 2.1.2 — 2024-04-15
- 2.1.0 — 2024-04-08
- 2.0.0 — 2023-12-08
- 1.0.0 — 2023-09-26
- 0.12.1 — 2023-08-24
- 0.12.0 — 2023-02-10
- 0.11.2 — 2022-12-23
- 0.11.1 — 2022-08-30
- 0.11.0 — 2022-08-25
- 0.10.0 — 2022-08-23
- … 10 more at https://npm.io/package/@mdit-vue/plugin-headers/versions

## README

# @mdit-vue/plugin-headers

[![npm](https://badgen.net/npm/v/@mdit-vue/plugin-headers)](https://www.npmjs.com/package/@mdit-vue/plugin-headers)
[![license](https://badgen.net/github/license/mdit-vue/mdit-vue)](https://github.com/mdit-vue/mdit-vue/blob/main/LICENSE)

A [markdown-it](https://github.com/markdown-it/markdown-it) plugin to get markdown headers.

- Extracts all headers info into markdown-it `env.headers`.

## Install

```sh
npm i @mdit-vue/plugin-headers
```

## Usage

```ts
import { headersPlugin } from '@mdit-vue/plugin-headers';
import type { MarkdownItEnv } from '@mdit-vue/types';
import MarkdownIt from 'markdown-it';

const md = MarkdownIt({ html: true }).use(headersPlugin, {
  // options
});
const env: MarkdownItEnv = {};

const rendered = md.render(
  `\
# h1
## h2
### h3
`,
  env,
);

console.log(env.headers);
```

## Options

### format

- Type: `(str: string) => string`

- Details:

  A function for formatting header title.

### level

- Type: `number[]`

- Default: `[2, 3]`

- Details:

  Heading level that going to be extracted.

  When using this plugin with [markdown-it-anchor](https://github.com/valeriangalliat/markdown-it-anchor) (recommended), this option should be a subset of markdown-it-anchor's `level` option to ensure the header slugs are existed.

### shouldAllowNested

- Type: `boolean`

- Default: `false`

- Details:

  Should allow headers inside nested blocks or not.

  If set to `true`, headers inside blockquote, list, etc. would also be extracted.

### slugify

- Type: `(str: string) => string`

- Default: `slugify` from `@mdit-vue/shared`

- Details:

  A custom slugification function.

  The default slugify function comes from [@mdit-vue/shared](https://github.com/mdit-vue/mdit-vue/tree/main/packages/shared) package.

  When using this plugin with [markdown-it-anchor](https://github.com/valeriangalliat/markdown-it-anchor) (recommended), this option will be ignored because the `id` of the headings have already been determined by markdown-it-anchor's `slugify` option.

---
_Source: https://npm.io/package/@mdit-vue/plugin-headers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
