# astro-custom-toc

> Astro Integration to generate a customizable table of contents

Latest version **5.0.2** (published 2026-10-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install astro-custom-toc
pnpm add astro-custom-toc
yarn add astro-custom-toc
bun add astro-custom-toc
```

## 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 | 5.0.2 |
| Published | 2026-10-28 |
| First published | 2024-03-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 8 |
| Unpacked size | 28.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 7 |
| Author | Robot-Inventor |
| Maintainers | robot-inventor |
| Keywords | astro, astro-integration, markdown, remark, ui, withastro |

## Links

- npm: https://www.npmjs.com/package/astro-custom-toc
- Repository: https://github.com/Robot-Inventor/astro-custom-toc
- Homepage: https://github.com/Robot-Inventor/astro-custom-toc#readme
- Issues: https://github.com/Robot-Inventor/astro-custom-toc/issues
- npm.io page: https://npm.io/package/astro-custom-toc

## Dependencies (8)

- [satteri](https://npm.io/package/satteri.md) ^0.10.0
- [unified](https://npm.io/package/unified.md) ^11.0.4
- [@types/hast](https://npm.io/package/@types/hast.md) ^3.0.4
- [github-slugger](https://npm.io/package/github-slugger.md) ^2.0.0
- [remark-comment](https://npm.io/package/remark-comment.md) ^1.0.0
- [rehype-custom-toc](https://npm.io/package/rehype-custom-toc.md) ^1.0.0
- [@astrojs/markdown-remark](https://npm.io/package/@astrojs/markdown-remark.md) ^7.2.0
- [@astrojs/markdown-satteri](https://npm.io/package/@astrojs/markdown-satteri.md) ^0.4.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 5.0.2 (latest) — 2026-10-28
- 5.0.1 — 2026-10-25
- 5.0.0 — 2026-09-14
- 4.0.6 — 2026-04-22
- 4.0.5 — 2026-04-04
- 4.0.4 — 2026-03-29
- 4.0.3 — 2026-03-21
- 4.0.2 — 2026-03-19
- 4.0.1 — 2026-03-12
- 4.0.0 — 2026-03-10
- 3.0.6 — 2026-03-05
- 3.0.5 — 2026-03-02
- 3.0.4 — 2026-02-28
- 3.0.3 — 2026-02-21
- 3.0.2 — 2026-01-16
- … 67 more at https://npm.io/package/astro-custom-toc/versions

## README

# astro-custom-toc

Astro Integration to generate a customizable table of contents. This is a convenient wrapper for [rehype-custom-toc](https://github.com/Robot-Inventor/rehype-custom-toc/). If you are not using Astro, you can directly use rehype-custom-toc instead.

> [!WARNING]
> This plugin uses [remark-comment](https://github.com/leebyron/remark-comment) when using the `unified` Markdown processor. It may break other plugins that use comments. When using the Sätteri processor (Astro v7 default), HTML comments are handled natively and `remark-comment` is not used.

> [!TIP]
> Since astro-custom-toc v5 supports only Astro v7, please use v4 if you are using Astro v6.

## Installation

```bash
npx astro add astro-custom-toc
```

### Manual Install

Install the package

```bash
npm install astro-custom-toc
```

Add the plugin to your `astro.config.mjs`.

```javascript
import { defineConfig } from "astro/config";
import customToc from "astro-custom-toc";

// https://astro.build/config
export default defineConfig({
    // ... other config
    integrations: [customToc()]
});
```

## Markdown processor support

astro-custom-toc works with both Markdown processors supported by Astro v7:

- **Sätteri** (default): Astro's native Markdown pipeline. No extra setup is needed.
- **Unified** (remark/rehype): Set `markdown.processor: unified()` from `@astrojs/markdown-remark` to use this processor.

## Usage

To include a table of contents in your markdown file, add `showToc: true` to the frontmatter of the markdown file. The table of contents will be inserted at the location of the `<!-- toc -->` comment or at the beginning of the file if no comment is found.

```markdown
---
showToc: true
---

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

<!-- toc -->

## Section 1

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

### Subsection 1.1

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
```

## Options

All options of rehype-custom-toc can be used in this plugin. Please refer to the [rehype-custom-toc documentation](https://github.com/Robot-Inventor/rehype-custom-toc/) for options.

## Development

```bash
npm install
```

### Build

```bash
npm run build
```

### Format and Lint

```bash
npm run format
npm run lint
```

### Pull Requests

This repository uses [Changesets](https://github.com/changesets/changesets) to manage versioning and releases. When creating a pull request, please run the Changesets CLI and commit the changeset file.

```bash
npx changeset
```

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