remark-selective-toc

0.3.0 • Public • Published

remark-selective-toc

Downloads Install size version MIT 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.

<!--
👇 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 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.

Package Sidebar

Install

npm i remark-selective-toc

Weekly Downloads

10

Version

0.3.0

License

MIT

Unpacked Size

6.56 kB

Total Files

4

Last publish

Collaborators

  • alvinometric