包详细信息

@mdit-vue/plugin-toc

mdit-vue113.7kMIT3.0.2

A markdown-it plugin to generate table-of-contents that compatible with Vue.js

markdown-it, markdown-it-plugin, vue, toc

自述文件

@mdit-vue/plugin-toc

npm license

A markdown-it plugin to generate table-of-contents (TOC) that compatible with Vue.js.

This plugin is basically a fork of markdown-it-toc-done-right, with following enhancement:

  • Allows html_inline tags in headings to support vue components.
  • Supports containerTag, listTag and linkTag.
  • Only allows array in level option.
  • Code refactor and optimizations.

Install

npm i @mdit-vue/plugin-toc

Usage

import { tocPlugin } from '@mdit-vue/plugin-toc';
import MarkdownIt from 'markdown-it';

const md = MarkdownIt({ html: true }).use(tocPlugin, {
  // options
});

Options

pattern

  • Type: RegExp

  • Default: /^\[\[toc\]\]$/i

  • Details:

    The pattern serving as the TOC placeholder in your markdown.

slugify

  • Type: (str: string) => string

  • Default: slugify from @mdit-vue/shared

  • Details:

    A custom slugification function.

    The default slugify function comes from @mdit-vue/shared package.

    When using this plugin with markdown-it-anchor (recommended), this option will be ignored because the id of the headings have already been determined by markdown-it-anchor's slugify option.

format

  • Type: (str: string) => string

  • Details:

    A function for formatting headings.

level

  • Type: number[]

  • Default: [2, 3]

  • Details:

    Heading level that going to be included in the TOC.

    When using this plugin with markdown-it-anchor (recommended), this option should be a subset of markdown-it-anchor's level option to ensure the target links are existed.

shouldAllowNested

  • Type: boolean

  • Default: false

  • Details:

    Should allow headers inside nested blocks or not.

    If set to true, headers inside blockquote, list, etc. would also be included.

containerTag

  • Type: string

  • Default: 'nav'

  • Details:

    HTML tag of the TOC container.

containerClass

  • Type: string

  • Default: 'table-of-contents'

  • Details:

    The class for the TOC container.

listTag

  • Type: 'ul' | 'ol'

  • Default: 'ul'

  • Details:

    HTML tag of the TOC list.

listClass

  • Type: string

  • Default: ''

  • Details:

    The class for the TOC list.

itemClass

  • Type: string

  • Default: ''

  • Details:

    The class for the <li> tag.

linkTag

  • Type: 'a' | 'router-link'

  • Default: 'a'

  • Details:

    The tag of the link inside the <li> tag.

    You can set this option to render to links as vue-router's router-link.

linkClass

  • Type: string

  • Default: ''

  • Details:

    The class for the link inside the <li> tag.

更新日志

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

3.0.2 (2025-08-11)

Bug Fixes

  • plugin-title: avoid output types being tree-shaken (6255fd4)

3.0.1 (2025-08-11)

Note: Version bump only for package @mdit-vue/monorepo

3.0.0 (2025-08-11)

Build System

BREAKING CHANGES

  • drop node 18 and migrate to pure ESM packages

2.1.4 (2025-04-10)

Bug Fixes

  • plugin-frontmatter: extract frontmatter in parse step (close #13) (#14) (1192bd2)

2.1.3 (2024-05-13)

Note: Version bump only for package @mdit-vue/monorepo

2.1.2 (2024-04-15)

Bug Fixes

  • sync markdown-it types updates (#9) (f6768b1)

2.1.1 (2024-04-13)

Bug Fixes

  • plugin-component: inline html block tags to make cjs build work (eb1a264)

2.1.0 (2024-04-08)

Features

  • upgrade markdown-it types to v14 (6839be8)

2.0.0 (2023-12-08)

Features

BREAKING CHANGES

  • bump to markdown-it 14

1.0.0 (2023-09-26)

Bug Fixes

  • plugin-toc: remove duplicate itemClass (#7) (7e0f1f0)

BREAKING CHANGES

  • drop support for node 16

0.12.1 (2023-08-24)

Note: Version bump only for package mdit-vue

0.12.0 (2023-02-10)

Features

  • plugin-headers: add shouldAllowNested option (93e004d)
  • plugin-toc: add shouldAllowNested option (close #5) (1f3b867)
  • shared: add shouldAllowNested option for resolveHeadersFromTokens (9363b92)

0.11.2 (2022-12-23)

Bug Fixes

  • shared: avoid resolve headers in nested blocks (ce146bd)

0.11.1 (2022-08-30)

Note: Version bump only for package mdit-vue

0.11.0 (2022-08-25)

Features

  • plugin-sfc: extract all script blocks (8c39df6)

0.10.0 (2022-08-23)

Features

  • plugin-headers: resolve link property for headers (da2954f)
  • types: add link property to header (7461417)

0.9.4 (2022-08-23)

Bug Fixes

  • plugin-component: handle multiline component tags correctly (53724fa)

0.9.3 (2022-08-20)

Bug Fixes

  • plugin-headers: avoid headers being overridden by another rendering (de1030b)
  • plugin-title: avoid title being overridden by another rendering (43cc020)

0.9.2 (2022-08-18)

Bug Fixes

  • plugin-toc: avoid toc being overridden by another rendering (c145c26)

0.9.1 (2022-07-26)

Bug Fixes

  • plugin-sfc: expose MarkdownSfcBlocks type (c2a91de)

0.9.0 (2022-07-26)

Features

  • plugin-sfc: extract SFC blocks as structured data (5a0aa54)

BREAKING CHANGES

  • plugin-sfc: the type of env.sfcBlocks has been changed

0.8.1 (2022-07-22)

Bug Fixes

  • plugin-component: make component tags behave like inline tags in some cases (9db6f9c)

0.8.0 (2022-07-22)

Features

  • plugin-component: add blockTags and inlineTags options (4651422)

0.7.1 (2022-07-20)

Note: Version bump only for package mdit-vue

0.7.0 (2022-07-18)

Features

  • plugin-frontmatter: extract content without frontmatter into env.content (a9d5cef)

0.6.0 (2022-07-11)

Features

  • types: extract types from shared package (5fc56ce)

0.5.0 (2022-07-06)

Features

  • plugin-frontmatter: add frontmatter plugin (bcffc7a)

0.4.0 (2022-07-02)

Features

  • plugin-headers: add headers plugin (636aa9b)
  • plugin-title: add title plugin (662e153)

0.3.1 (2022-06-25)

Bug Fixes

  • plugin-toc: export types (310320e)

0.3.0 (2022-06-25)

Features

  • plugin-toc: add toc plugin (e64cc2c)
  • shared: add html escape and unescape utils (e1103c2)

0.2.0 (2022-06-23)

Features

  • plugin-sfc: add sfc plugin (1eb4e0a)
  • shared: add shared package (9e36bdc)

0.1.1 (2022-06-23)

Bug Fixes

  • plugin-component: add js extension to work with esm (42ccdad)

0.1.0 (2022-06-22)

Features

  • plugin-component: add component plugin (cd2eeaa)