fumadocs-core
Version:
The React.js library for building a documentation website
131 lines • 4.75 kB
TypeScript
import { n as IconOptions } from "./transformer-icon-Bi4LROAz.js";
import { t as Awaitable } from "./types-Dvkw0Kd0.js";
import { i as Highlighter, t as HighlightCodeOptions } from "./index-BhAz6nyI.js";
import { n as ShikiFactory } from "./index-e-8QoCiA.js";
import { Element, Root } from "hast";
import { Processor, Transformer } from "unified";
import { BuiltinLanguage, BuiltinTheme, CodeOptionsMeta, CodeOptionsThemes, CodeToHastOptionsCommon, HighlighterCore, LanguageInput, ShikiTransformer, TransformerOptions } from "shiki";
type InlineCodeParser = 'tailing-curly-colon';
interface MapLike<K = unknown, V = unknown> {
get: (key: K) => V | undefined;
set: (key: K, value: V) => this;
}
interface RehypeCodeFromHighlighterOptions {
/**
* The default language to use when is not specified
*
* @defaultValue 'plaintext'
*/
defaultLanguage?: string;
/**
* `mdast-util-to-hast` adds a newline to the end of code blocks
*
* This option strips that newline from the code block
*
* @default true
* @see https://github.com/syntax-tree/mdast-util-to-hast/blob/f511a93817b131fb73419bf7d24d73a5b8b0f0c2/lib/handlers/code.js#L22
*/
stripEndNewline?: boolean;
/**
* Custom meta string parser
* Return an object to merge with `meta`
*/
parseMetaString?: (metaString: string, node: Element, tree: Root) => Record<string, unknown> | undefined | null;
/**
* Filter meta string before processing
*/
filterMetaString?: (metaString: string) => string;
/**
* Highlight inline code blocks
*
* - `false`: disable inline code block highlighting
* - `tailing-curly-colon`: highlight with `\`code{:lang}\``
*
* @see https://shiki.style/packages/rehype#inline-code
* @default false
*/
inline?: InlineCodeParser | false;
/**
* Custom map to cache transformed codeToHast result
*
* @default undefined
*/
cache?: MapLike<string, Root>;
/**
* Chance to handle the error
* If not provided, the error will be thrown
*/
onError?: (error: unknown) => void;
/**
* Shiki transformers to create the highlighter with, when it is a function
*
* @defaultValue notation transformers of `@shikijs/transformers`
*/
transformers?: ShikiTransformer[];
/**
* Add icon to code blocks, when the highlighter is a function
*/
icon?: IconOptions | false;
}
/**
* Highlight code blocks, a function is created with the transformers of Fumadocs.
*/
declare function rehypeCodeFromHighlighter(highlighter: Highlighter | ((options: {
transformers: ShikiTransformer[];
}) => Highlighter), options?: RehypeCodeFromHighlighterOptions): Transformer<Root, Root>;
declare module 'shiki' {
interface ShikiTransformer {
/** [Fumadocs: rehype-code] async work before highlighting the code block, resolves to more languages to load */
_fd_prepare?: (code: string, options: HighlightCodeOptions) => Promise<string[] | void> | void;
}
}
interface RehypeShikiExtraOptions extends RehypeCodeFromHighlighterOptions {
/**
* Add `language-*` class to code element
*
* @default false
*/
addLanguageClass?: boolean;
/**
* The fallback language to use when specified language is not loaded, or not included in the bundle
*/
fallbackLanguage?: string;
/**
* Load languages and themes on-demand.
*
* @default true
*/
lazy?: boolean;
}
type RehypeShikiCoreOptions = CodeOptionsThemes<BuiltinTheme> & TransformerOptions & CodeOptionsMeta & RehypeShikiExtraOptions & Omit<CodeToHastOptionsCommon, 'lang'>;
declare function rehypeCodeDefaultOptions(): RehypeCodeOptionsCommon;
type RehypeCodeOptionsCommon = RehypeShikiCoreOptions & {
/**
* Language names to include & preload.
*/
langs?: Array<LanguageInput | BuiltinLanguage>;
/**
* Alias of languages
* @example { 'my-lang': 'javascript' }
*/
langAlias?: Record<string, string>;
/**
* Add icon to code blocks
*/
icon?: IconOptions | false;
/**
* Wrap code blocks in `<Tab>` component when "tab" meta string presents
*
* @defaultValue true
*/
tab?: boolean;
};
/**
* @deprecated use `rehypeCodeFromHighlighter()` with `createShikiHighlighter()`
*/
declare function createRehypeCode<Options extends Partial<RehypeCodeOptionsCommon> = Partial<RehypeCodeOptionsCommon>>(highlighterFactory: ShikiFactory | ((options?: Options) => Awaitable<{
highlighter: HighlighterCore;
options: RehypeCodeOptionsCommon;
}>)): (this: Processor, _options?: Options) => Transformer<Root, Root>;
declare function transformerTab(): ShikiTransformer;
export { rehypeCodeFromHighlighter as a, rehypeCodeDefaultOptions as i, RehypeCodeOptionsCommon as n, transformerTab as o, createRehypeCode as r, RehypeCodeFromHighlighterOptions as t };