@mdit-vue/plugin-toc
Version:
A markdown-it plugin to generate table-of-contents that compatible with Vue.js
123 lines (122 loc) • 2.98 kB
TypeScript
import { MarkdownItHeader } from "@mdit-vue/types";
import { RuleBlock } from "markdown-it/lib/parser_block.mjs";
import { PluginWithOptions } from "markdown-it";
//#region src/types.d.ts
/**
* Options of @mdit-vue/plugin-toc
*/
interface TocPluginOptions {
/**
* The pattern serving as the TOC placeholder in your markdown
*
* @default /^\[\[toc\]\]$/i
*/
pattern?: RegExp;
/**
* A custom slugification function
*
* Should use the same slugify function with markdown-it-anchor
* to ensure the link is matched
*/
slugify?: (str: string) => string;
/**
* A function for formatting headings
*/
format?: (str: string) => string;
/**
* Heading level that going to be included in the TOC
*
* Should be a subset of markdown-it-anchor's `level` option
* to ensure the link is existed
*
* @default [2,3]
*/
level?: number[];
/**
* Should allow headers inside nested blocks or not
*
* If set to `true`, headers inside blockquote, list, etc. would also be included.
*
* @default false
*/
shouldAllowNested?: boolean;
/**
* HTML tag of the TOC container
*
* @default 'nav'
*/
containerTag?: string;
/**
* The class for the TOC container
*
* @default 'table-of-contents'
*/
containerClass?: string;
/**
* HTML tag of the TOC list
*
* @default 'ul'
*/
listTag?: 'ol' | 'ul';
/**
* The class for the TOC list
*
* @default ''
*/
listClass?: string;
/**
* The class for the `<li>` tag
*
* @default ''
*/
itemClass?: string;
/**
* The tag of the link inside `<li>` tag
*
* @default 'a'
*/
linkTag?: 'a' | 'router-link';
/**
* The class for the link inside the `<li>` tag
*
* @default ''
*/
linkClass?: string;
}
//#endregion
//#region src/create-render-headers.d.ts
type RenderHeadersFn = (headers: MarkdownItHeader[]) => string;
declare const createRenderHeaders: ({
listTag,
listClass,
itemClass,
linkTag,
linkClass
}: Pick<Required<TocPluginOptions>, "itemClass" | "linkClass" | "linkTag" | "listClass" | "listTag">) => RenderHeadersFn;
//#endregion
//#region src/create-toc-block-rule.d.ts
/**
* Forked and modified from markdown-it-toc-done-right
*
* - remove the `inlineOptions` support
* - use markdown-it default renderer to render token whenever possible
*
* @see https://github.com/nagaozen/markdown-it-toc-done-right
*/
declare const createTocBlockRule: ({
pattern,
containerTag,
containerClass
}: Pick<Required<TocPluginOptions>, "containerClass" | "containerTag" | "pattern">) => RuleBlock;
//#endregion
//#region src/toc-plugin.d.ts
/**
* Generate table of contents
*
* Forked and modified from markdown-it-toc-done-right:
*
* @see https://github.com/nagaozen/markdown-it-toc-done-right
*/
declare const tocPlugin: PluginWithOptions<TocPluginOptions>;
//#endregion
export { TocPluginOptions, createRenderHeaders, createTocBlockRule, tocPlugin };