@sveltek/unplugins
Version:
Sveltek's Unified plugins for Markdown preprocessor.
230 lines (229 loc) • 5.13 kB
TypeScript
import * as Unified from "unified";
import { Plugin } from "unified";
import * as VFile from "vfile";
import * as Mdast from "mdast";
import { Root } from "mdast";
import * as Hast from "hast";
import { Root as Root$1 } from "hast";
import { CodeOptionsMultipleThemes, CodeOptionsSingleTheme, CodeToHastOptions, createHighlighter } from "shiki";
import { HighlightOptions, HighlighterData } from "@sveltek/markdown";
export * from "unist-util-visit";
//#region src/remark/toc/types.d.ts
interface TocOptions {
/**
* Specifies the maximum headings depth to be included in the table of content.
*
* @default 3
*/
depth?: number;
/**
* Specifies whether headings include link tags.
*
* @default true
*/
links?: boolean;
}
interface TocItem {
id: string;
depth: number;
value: string;
}
type TocItems = TocItem[];
//#endregion
//#region src/remark/reading-stats/types.d.ts
interface ReadingStats {
minutes: number;
words: number;
text: string;
}
interface ReadingStatsOptions {
/**
* Specifies how many words per minute an average reader can read.
*
* @default 200
*/
wordsPerMinute?: number;
}
//#endregion
//#region src/remark/toc/index.d.ts
/**
* A custom `Remark` plugin that creates `Table of Content` (Toc).
*
* Automatically adds a link with the appropriate attributes to the headings.
*
* It also stores Toc items to `frontmatter` for easy access.
*
* @example
*
* ```ts
* import { svelteMarkdown } from '@sveltek/markdown'
* import { remarkToc } from '@sveltek/unplugins'
*
* svelteMarkdown({
* plugins: {
* remark: [remarkToc]
* }
* })
* ```
*
* Or with options:
*
* ```js
* svelteMarkdown({
* plugins: {
* remark: [[remarkToc, { depth: 3 }]]
* }
* })
* ```
*/
declare const remarkToc: Plugin<[TocOptions?], Root>;
//#endregion
//#region src/remark/reading-stats/index.d.ts
/**
* A custom `Remark` plugin that creates `Reading Stats`.
*
* Stores reading details to `frontmatter` for easy access.
*
* @example
*
* ```ts
* import { svelteMarkdown } from '@sveltek/markdown'
* import { remarkReadingStats } from '@sveltek/unplugins'
*
* svelteMarkdown({
* plugins: {
* remark: [remarkReadingStats]
* }
* })
* ```
*
* Or with options:
*
* ```js
* svelteMarkdown({
* plugins: {
* remark: [[remarkReadingStats, { wordsPerMinute: 300 }]]
* }
* })
* ```
*/
declare const remarkReadingStats: Plugin<[ReadingStatsOptions?], Root>;
//#endregion
//#region src/rehype/shiki/types.d.ts
type HighlighterOptions = Parameters<typeof createHighlighter>[0];
interface ShikiOptions {
/**
* Specifies a custom theme.
*
* @example
*
* ```ts
* {
* theme: 'github-light-default',
* }
* ```
*
* @default 'github-dark-default'
*/
theme?: CodeOptionsSingleTheme['theme'];
/**
* Specifies a map of color names to themes.
*
* Allows multiple themes for the generated code.
*
* @example
*
* ```ts
* {
* themes: {
* light: 'github-light-default',
* dark: 'github-dark-default',
* }
* }
* ```
*
* @default undefined
*/
themes?: CodeOptionsMultipleThemes['themes'];
/**
* Specifies a custom Shiki language registration.
*
* @example
*
* ```ts
* {
* langs: ['javascript', 'typescript', 'svelte']
* }
* ```
*
* @default ['javascript', 'typescript', 'svelte']
*/
langs?: HighlighterOptions['langs'];
/**
* Specifies custom Shiki `highlighter` options.
*
* @default undefined
*/
highlighter?: HighlighterOptions;
/**
* Specifies custom Shiki `codeToHtml` options.
*
* @default undefined
*/
codeToHtml?: Partial<CodeToHastOptions & CodeOptionsSingleTheme & CodeOptionsMultipleThemes> | ((data: HighlighterData) => Partial<CodeToHastOptions & CodeOptionsSingleTheme & CodeOptionsMultipleThemes>);
/**
* Parses `meta` string from the code block.
*
* @default undefined
*/
parseMeta?: (meta: string | undefined) => void | string;
/**
* Specifies custom options for the `root` node (usually the `<pre>` tag).
*
* @example
*
* ```ts
* {
* root: (node) => {
* node.tagName = 'div'
* node.properties.id = 'code-highlight'
* // ...
* }
* }
* ```
*
* @default undefined
*/
root?: HighlightOptions['root'];
}
//#endregion
//#region src/rehype/shiki/index.d.ts
/**
* A custom `Rehype` plugin for `Shiki`.
*
* @example
*
* ```js
* import { svelteMarkdown } from '@sveltek/markdown'
* import { rehypeShiki } from '@sveltek/unplugins'
*
* svelteMarkdown({
* plugins: {
* rehype: [rehypeShiki]
* }
* })
* ```
*
* Or with options:
*
* ```js
* svelteMarkdown({
* plugins: {
* rehype: [[rehypeShiki, { theme: 'github-light-default' }]]
* }
* })
* ```
*/
declare const rehypeShiki: Plugin<[ShikiOptions?], Root$1>;
//#endregion
export { type Hast, type Mdast, type Plugin, ReadingStats, ReadingStatsOptions, ShikiOptions, TocItem, TocItems, TocOptions, type Unified, type VFile, rehypeShiki, remarkReadingStats, remarkToc };