UNPKG

@sveltek/unplugins

Version:

Sveltek's Unified plugins for Markdown preprocessor.

230 lines (222 loc) 5.08 kB
import { Plugin } from 'unified'; import * as unified from 'unified'; export { unified as Unified }; export { Plugin } from 'unified'; import * as vfile from 'vfile'; export { vfile as VFile }; import { Root } from 'mdast'; import * as mdast from 'mdast'; export { mdast as Mdast }; import { Root as Root$1 } from 'hast'; import * as hast from 'hast'; export { hast as Hast }; import { CodeOptionsSingleTheme, CodeOptionsMultipleThemes, createHighlighter, CodeToHastOptions } from 'shiki'; import { HighlighterData, HighlightOptions } from '@sveltek/markdown'; 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[]; 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; } /** * 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>; /** * 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>; 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?: (CodeToHastOptions & CodeOptionsSingleTheme & CodeOptionsMultipleThemes) | ((data: HighlighterData) => 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']; } /** * 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>; export { rehypeShiki, remarkReadingStats, remarkToc }; export type { ReadingStats, ReadingStatsOptions, ShikiOptions, TocItem, TocItems, TocOptions };