remark-selective-toc
v0.3.0
Published
Remark Plugin to selectively add a table of contents
Downloads
21
Maintainers
Readme
remark-selective-toc
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
.
<!--
👇 This code block gets replaced
with a TOC of h2 headings only
-->
```toc
from: 1
to: 2
```
Installation
This package is ESM only. In Node.js (version 16.0+, or 18.0+), install with npm:
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.
<!-- 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
orarray
- 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
andto-heading
as options. This plugins accepts both these values as well as justfrom
andto
.
Contributing
Feel free to open issues and pull requests.
License
MIT License. See LICENSE
for more information.