# md-index-generator

> Parses a markdown document and creates an index based on headings

Latest version **3.3.2** (published 2026-11-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install md-index-generator
pnpm add md-index-generator
yarn add md-index-generator
bun add md-index-generator
```

Provides the command `md-index-generator`.

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.3.2 |
| Published | 2026-11-03 |
| First published | 2020-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.0.0 |
| Dependencies | 3 |
| Unpacked size | 18.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 9 |
| Author | Alessio Michelini |
| Maintainers | darkmavis1980 |
| Keywords | markdown, index |

## Links

- npm: https://www.npmjs.com/package/md-index-generator
- Repository: https://github.com/darkmavis1980/markdown-index-generator
- Issues: https://github.com/experimental/markdown-index-generator/issues
- npm.io page: https://npm.io/package/md-index-generator

## Dependencies (3)

- [tsx](https://npm.io/package/tsx.md) ^4.23.15
- [tslib](https://npm.io/package/tslib.md) ^2.9.1
- [commander](https://npm.io/package/commander.md) ^15.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

- 3.3.2 (latest) — 2026-11-03
- 3.3.1 — 2026-08-21
- 3.3.0 — 2026-07-29
- 3.2.5 — 2026-06-07
- 3.2.4 — 2026-03-29
- 3.2.3 — 2026-01-22
- 3.2.1 — 2025-08-29
- 3.2.0 — 2025-08-12
- 3.1.4 — 2025-08-08
- 3.1.3 — 2025-08-08
- 3.1.2 — 2025-04-30
- 3.1.1 — 2025-04-25
- 3.1.0 — 2025-04-25
- 3.0.3 — 2025-04-22
- 3.0.1 — 2025-03-29
- … 59 more at https://npm.io/package/md-index-generator/versions

## README

# md-index-generator
========================

Parses a markdown document and creates an index based on headings.

> The h1 heading will be ignored as it should be used only for the main title of the document

[![Version](https://img.shields.io/npm/v/md-index-generator.svg)](https://npmjs.org/package/md-index-generator)
[![Downloads/week](https://img.shields.io/npm/dw/md-index-generator.svg)](https://npmjs.org/package/md-index-generator)
[![License](https://img.shields.io/npm/l/md-index-generator.svg)](https://github.com/experimental/markdown-index-generator/blob/master/package.json)
![Build Status](https://github.com/darkmavis1980/markdown-index-generator/workflows/CI/badge.svg)

## Usage

```sh-session
$ npm install -g md-index-generator
$ md-index-generator COMMAND
running command...
$ md-index-generator (-v|--version|version)
1.0.0

// Replace the passed markdown file
$ md-index-generator <MarkDown.md>

// Display the output on the shell
$ md-index-generator <MarkDown.md> --dry-run

// Store the output in a file
$ md-index-generator <MARKDOWNFILE.md> --output <Index.md>

// Generate the index using only h2 and h3 headings
$ md-index-generator <MarkDown.md> --depth 3

// Set the title of the index, output will start with "## Docs index"
$ md-index-generator <MarkDown.md> --title "Docs index"
```

## Breaking Changes

From version `1.x` onward, the logic of the CLI has changed, where by default it replace the index of the source file, while before you had to explicitly use the `--replace` flag to do so. If you want to see the index generated on screen, you must pass the `--dry-run` flag instead.

### Optional flags

`-o, --output <VALUE>` This takes an output file, where the parsed index will be stored instead of being shown in the shell

`-d, --depth <VALUE>` This sets the depth, with a range between 2 and 5, so if sets to 3, it will parse the headings until H3, default value is 4

`-t, --title <VALUE>` This set the title for the index list, by default is set to `Index`

`-r, --dry-run` This flag will show the output on screen, but it will not update the source file

#### Add the index in the source file

If you wish to modify the file you are passing as a source, you must add the tags `<!-- index-start -->` and `<!-- index-end -->` in the markdown document.
Here a sample:

```markdown
# Your Fancy document

<!-- index-start -->
The index will go here!
<!-- index-end -->

## Some more stuff

Hello
```

> If you don't add the index tags, the script will automatically put the index before the first Heading 2 in the document. It is recommended to add the tags to properly control where the index will be added.

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