# remark-selective-toc

> Remark Plugin to selectively add a table of contents

Latest version **0.4.0** (published 2026-10-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install remark-selective-toc
pnpm add remark-selective-toc
yarn add remark-selective-toc
bun add remark-selective-toc
```

## Health

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

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

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2026-10-26 |
| First published | 2023-09-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Alvin Bryan |
| Maintainers | alvinometric |
| Keywords | markdown, plugin, remark, remark-plugin, toc, unified |

## Links

- npm: https://www.npmjs.com/package/remark-selective-toc
- Repository: https://github.com/alvinometric/remark-selective-toc
- Homepage: https://github.com/alvinometric/remark-selective-toc#readme
- Issues: https://github.com/alvinometric/remark-selective-toc/issues
- npm.io page: https://npm.io/package/remark-selective-toc

## Dependencies (4)

- [js-yaml](https://npm.io/package/js-yaml.md) ^4.1.0
- [mdast-util-toc](https://npm.io/package/mdast-util-toc.md) ^7.0.0
- [unist-util-filter](https://npm.io/package/unist-util-filter.md) ^5.0.1
- [unist-util-modify-children](https://npm.io/package/unist-util-modify-children.md) ^4.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

- 0.4.0 (latest) — 2026-10-26
- 0.3.0 — 2023-09-18
- 0.2.0 — 2023-09-18

## README

# remark-selective-toc

<!-- prettier-ignore-start -->
[![Downloads](https://img.shields.io/npm/dm/remark-selective-toc.svg?style=flat-square)](https://www.npmjs.com/package/remark-selective-toc)
[![Install size](https://packagephobia.com/badge?p=remark-selective-toc)](https://packagephobia.com/result?p=remark-selective-toc)
[![version](https://img.shields.io/npm/v/remark-selective-toc.svg?style=flat-square)](https://www.npmjs.com/package/remark-selective-toc)
[![MIT License](https://img.shields.io/npm/l/remark-selective-toc.svg?style=flat-square)](https://github.com/alvinometric/remark-selective-toc/blob/main/LICENSE)
<!-- prettier-ignore-end -->

A remark plugin to selectively add a table of contents and configure it for each markdown file. Ported and updated from [`gatsby-remark-table-of-contents`](https://github.com/signalwerk/gatsby-remark-table-of-contents).

````markdown
<!--
👇 This code block gets replaced
with a TOC of h2 headings only
-->

```toc
from: 1
to: 2
```
````

## Installation

This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
In Node.js (version 16.0+, or 18.0+), install with [npm](https://npmjs.com):

```bash
npm install remark-selective-toc
```

## When should I use this?

- You need more specific control over the TOC, such as excluding certain heading levels.
- You're working with multiple markdown files that each require different TOC configurations
- Some of your markdown files don't warrant a TOC at all.

## Options

### `from`

- Type: `number`
- Default: `2`

Sets the minimum heading depth to include.

### `to`

- Type: `number`
- Default: `6`

Sets the maximum heading depth to include.

### `className`

- Type: `string`
- Default: `toc`

Sets the class name of the div wrapping your table of contents.

### `tight`

- Type: `boolean`
- Default: `false`

`tight` lets you specify whether or not you want spaces before and between the list items.

```markdown
<!-- tight: true -->

- [Here's an h2](#heres-an-h2)

- [Another h2](#another-h2)

  - [and H3](#and-h3)

<!-- tight: false -->

- [Here's an h2](#heres-an-h2)
- [Another h2](#another-h2)
  - [and H3](#and-h3)
```

### `exclude`

- Type: `string` or `array`
- Default: `''`

Excludes titles matching this regex pattern.

### `ordered`

- Type: `boolean`
- Default: `false`

Chooses between ordered and unordered list.

## Differences with `gatsby-remark-table-of-contents`

- `tight` is true by default
- The Gatsby plugin uses `from-heading` and `to-heading` as options. This plugins accepts both these values as well as just `from` and `to`.

## Contributing

Feel free to open issues and pull requests.

## License

MIT License. See `LICENSE` for more information.

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