@mintlify/common
Version:
Commonly shared code within Mintlify
26 lines (25 loc) • 1.22 kB
TypeScript
import type { RootContent } from 'mdast';
import { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
export interface PreprocessCustomHeadingIdsOptions {
/**
* When true, preserves the original ID as-is (only removing characters unsafe
* in HTML attributes). When false (default), also collapses whitespace to hyphens.
*/
preserveOriginal?: boolean;
}
/**
* Converts markdown headings with custom ID syntax into JSX heading elements.
*
* Transforms `## Heading text {#custom-id}` into `<h2 id="custom-id">Heading text</h2>`.
* This avoids MDX parsing errors (MDX treats `{...}` as JS expressions) and
* produces JSX heading elements that the existing remark pipeline already handles.
*
* Uses a line-by-line scan with fence state tracking to skip headings inside
* code blocks, avoiding backtracking over large documents.
*/
export declare function preprocessCustomHeadingIds(content: string, options?: PreprocessCustomHeadingIdsOptions): string;
export interface JsxHeadingElement extends MdxJsxFlowElement {
readonly __jsxHeading: true;
}
export declare const ALL_HEADING_NAMES: string[];
export declare const isJsxHeadingElement: (node: RootContent) => node is JsxHeadingElement;