fumadocs-core
Version:
The React.js library for building a documentation website
81 lines • 3.9 kB
TypeScript
import { MarkdownTarget } from "../server.js";
import { VFile } from "vfile";
import { Expression } from "estree-jsx";
import { Nodes } from "mdast";
/** the code of the IDs from code, by the static ID of their heading: `remarkHeading` shares it in the data of a file */
type HeadingIds = Record<string, string | undefined>;
/**
* The Markdown of a node. A string covers the edits inside the node made before it and blocks those made after, a
* function runs when stringifying instead, and its `s.stringify()` & `s.inner()` apply the edits inside.
*/
export type Replacement = string | ((s: Stringifier) => string);
declare module 'vfile' {
interface DataMap {
/**
* Set by a content source that renders pages for props, like path params: the outputs of the Fumadocs plugins
* (the TOC, structured data, processed Markdown) are functions of the props, to call with the props of a page.
*
* The source decides for all of its documents, so the shape of an export never depends on the content.
*/
unstable_runtimeOutputs?: boolean;
/** @internal set by `remarkShow` on a document with branches, which only props tell apart */
_show?: boolean;
/** @internal set by `remarkHeading`, see {@link HeadingIds} */
_headingIds?: HeadingIds;
}
}
interface Range {
start: number;
end: number;
}
/**
* Replace the Markdown of an authored node, ignored without a position. The last edit of a node wins.
*
* @param namespace - limit the edit to the stringifiers of a namespace: `search` for search records, `markdown` for
* processed Markdown
*/
export declare function replaceSource(file: VFile, node: Nodes, text: Replacement, namespace?: MarkdownTarget | (string & {})): void;
/**
* Replace an authored node with `content`, its children parsed from another source (e.g. included files). Their
* positions are kept, stringifiers place `source` after the document's own.
*/
export declare function embedSource(file: VFile, node: Nodes, source: string, content: Nodes[]): void;
/**
* Markdown output backed by the authored source. Nodes without a position (e.g. generated by plugins) only appear
* through replacements.
*/
export interface Stringifier {
/** the document's source, followed by embedded sources */
readonly source: string;
/** the range of a node in `source` */
range: (node: Nodes) => Range | undefined;
/** replace a node in this output, after the edits of plugins */
replace: (node: Nodes, text: Replacement) => void;
/** replace a range of `source` in this output, an empty range inserts text, the edit goes with `node` if given */
edit: (start: number, end: number, text: string, node?: Nodes) => void;
/** a range of `source` as Markdown */
slice: (start: number, end: number) => string;
/** a node as Markdown, empty without a position */
stringify: (node: Nodes) => string;
/** the children of a node as Markdown, empty without positions */
inner: (node: Nodes) => string;
/** whether `range` is output inside `outer`, embedded sources are output in place of the node they replace */
within: (range: Range, outer: Range) => boolean;
/**
* Markdown evaluated where the output is exported, like the URL of an imported file. `fallback` in outputs that
* can't evaluate it.
*/
expression: (expression: Expression, fallback: string) => string;
}
/**
* @param namespace - also apply the edits of this namespace
* @param expression - output the expressions of replacements, their fallbacks are output without it
*/
export declare function createStringifier(file: VFile, namespace?: MarkdownTarget | (string & {}), expression?: Stringifier['expression']): Stringifier;
/**
* A Markdown table with aligned columns, its first row is the header.
*
* @param rows - the cells of each row, as inline Markdown
*/
export declare function markdownTable(rows: string[][]): string;
export {};