remark-flexible-toc
Version:
Remark plugin to expose the table of contents via Vfile.data or via an option reference
41 lines • 1.97 kB
TypeScript
import type { Plugin } from "unified";
import type { Root } from "mdast";
export type Prettify<T> = {
[K in keyof T]: T[K];
} & {};
export type PartiallyRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
export type HeadingParent = "root" | "blockquote" | "footnoteDefinition" | "listItem" | "container" | "mdxJsxFlowElement";
export type HeadingDepth = 1 | 2 | 3 | 4 | 5 | 6;
export type TocItem = {
value: string;
href: string;
depth: HeadingDepth;
numbering: number[];
parent: HeadingParent;
data?: {
[PropertyName: string]: string | number | boolean | (string | number)[] | null | undefined;
};
};
/**
* tocName (default: "toc") - the key name which is attached into vfile.data
* tocRef (default: []) — another way of exposing the tocItems
* maxDepth (default: 6) — max heading depth to include in the table of contents; this is inclusive: when set to 3, level three headings are included
* skipLevels (default: [1]) — disallowed heading levels, by default the article h1 is not expected to be in the TOC
* skipParents (default: []) — disallow headings to be children of certain node types, (the "root" can not be skipped)
* exclude — headings to skip, wrapped in new RegExp('^(' + value + ')$', 'i'); any heading matching this expression will not be present in the table of contents
* prefix - the text that will be attached to headings as prefix, like "text-prefix-"
* callback - It is a callback function to take the array of toc items as an argument
*/
export type FlexibleTocOptions = {
tocName?: string;
tocRef?: TocItem[];
maxDepth?: HeadingDepth;
skipLevels?: HeadingDepth[];
skipParents?: Exclude<HeadingParent, "root">[];
exclude?: string | string[];
prefix?: string;
callback?: (toc: TocItem[]) => undefined;
};
declare const RemarkFlexibleToc: Plugin<[FlexibleTocOptions?], Root>;
export default RemarkFlexibleToc;
//# sourceMappingURL=index.d.ts.map