https://github.com/alvinometric/remark-selective-toc
Remark plugin that lets you create a Table of Contents with individual configurations for each Markdown file
https://github.com/alvinometric/remark-selective-toc
remark remark-plugins
Last synced: 10 months ago
JSON representation
Remark plugin that lets you create a Table of Contents with individual configurations for each Markdown file
- Host: GitHub
- URL: https://github.com/alvinometric/remark-selective-toc
- Owner: alvinometric
- License: mit
- Created: 2023-09-16T10:36:01.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-18T22:15:58.000Z (over 2 years ago)
- Last Synced: 2025-08-09T15:00:53.785Z (10 months ago)
- Topics: remark, remark-plugins
- Language: JavaScript
- Homepage:
- Size: 49.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# remark-selective-toc
[](https://www.npmjs.com/package/remark-selective-toc)
[](https://packagephobia.com/result?p=remark-selective-toc)
[](https://www.npmjs.com/package/remark-selective-toc)
[](https://github.com/alvinometric/remark-selective-toc/blob/main/LICENSE)
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
```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
- [Here's an h2](#heres-an-h2)
- [Another h2](#another-h2)
- [and H3](#and-h3)
- [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.