2.0.41 • Published 4 months ago

astro-custom-toc v2.0.41

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

astro-custom-toc

Astro Integration to generate a customizable table of contents.

!WARNING This plugin uses remark-comment. It may break other plugins that use comments.

Installation

npx astro add astro-custom-toc

Manual Install

Install the package

npm install astro-custom-toc

Add the plugin to your astro.config.mjs. This plugin must be inserted before the mdx() plugin if you are using it.

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

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

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.

---
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

type RemarkCustomTocTemplate = (html: string) => string;

interface RemarkCustomTocOptions {
    template?: RemarkCustomTocTemplate;
    maxDepth?: number;
    ordered?: boolean;
}

template

A function that takes the generated HTML and returns the final HTML. This can be used to wrap the generated HTML in a custom template.

Default:

const defaultTemplate = (html) => {
    return `
<aside class="toc">
    <h2>Contents</h2>
    <nav>
        ${html}
    </nav>
</aside>`.trim();
};

maxDepth

The maximum depth of headings to include in the table of contents.

Default: 3

ordered

Whether to use an ordered list (<ol>) or an unordered list (<ul>).

Default: false

Development

npm install

Build

npm run build

Format and Lint

npm run format
npm run lint

Pull Requests

This repository uses Changesets to manage versioning and releases. When creating a pull request, please run the Changesets CLI and commit the changeset file.

npx changeset
2.0.41

4 months ago

2.0.38

6 months ago

2.0.39

6 months ago

2.0.40

6 months ago

2.0.37

6 months ago

2.0.36

7 months ago

2.0.35

8 months ago

2.0.34

9 months ago

2.0.28

10 months ago

2.0.29

9 months ago

2.0.33

9 months ago

2.0.31

9 months ago

2.0.32

9 months ago

2.0.30

9 months ago

2.0.26

10 months ago

2.0.27

10 months ago

2.0.25

10 months ago

2.0.24

10 months ago

2.0.23

10 months ago

2.0.22

10 months ago

2.0.20

10 months ago

2.0.21

10 months ago

2.0.19

10 months ago

2.0.17

10 months ago

2.0.18

10 months ago

2.0.16

10 months ago

2.0.15

11 months ago

2.0.14

11 months ago

2.0.13

11 months ago

2.0.12

11 months ago

2.0.11

11 months ago

2.0.10

12 months ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.7

1 year ago

2.0.3

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.6

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago