/** * @file The Markdown AST vocabulary: node constructors, shape guards * and compiled walkers. * * Every node is a plain JSON object with a `type` discriminator; * container nodes hold ordered content in `children`, literal nodes in * `value` (normative vocabulary in docs/MD-FORMAT.md §4). The * constructors exist so every node of a type is born with the same * hidden class — the walkers and render tables then stay monomorphic. */ /** The document format version this package produces. */ export declare const MD_VERSION = "0.1"; export type MdNode = { type: string; [member: string]: any; }; export type MdDocument = { $md: string; frontmatter: any; ast: MdNode[]; meta: { sourceUrl: string | null; hash: string; frontmatterLang: 'yaml' | 'json' | 'toml' | null; }; }; /** * @typedef {{ type: string, [member: string]: any }} MdNode */ /** * @typedef {{ $md: string, frontmatter: any, ast: MdNode[], * meta: { sourceUrl: string|null, hash: string, * frontmatterLang: 'yaml'|'json'|'toml'|null } }} MdDocument */ /** * Does this node hold its content in `children`? Plugin/custom nodes * count when they actually carry a children array. * @param {MdNode} node * @returns {boolean} */ export declare function isContainerNode(node: MdNode): boolean; /** @param {MdNode[]} children @returns {MdNode} */ export declare function paragraph(children: MdNode[]): MdNode; /** @param {number} depth @param {MdNode[]} children @returns {MdNode} */ export declare function heading(depth: number, children: MdNode[]): MdNode; /** @returns {MdNode} */ export declare function thematicBreak(): MdNode; /** @returns {MdNode} */ export declare function pageBreak(): MdNode; /** @param {MdNode[]} children @returns {MdNode} */ export declare function blockquote(children: MdNode[]): MdNode; /** * @param {boolean} ordered * @param {number|null} start * @param {boolean} tight * @param {MdNode[]} children * @returns {MdNode} */ export declare function list(ordered: boolean, start: number | null, tight: boolean, children: MdNode[]): MdNode; /** @param {boolean|null} checked @param {MdNode[]} children @returns {MdNode} */ export declare function listItem(checked: boolean | null, children: MdNode[]): MdNode; /** * @param {string|null} lang * @param {string|null} meta * @param {string} value * @returns {MdNode} */ export declare function code(lang: string | null, meta: string | null, value: string): MdNode; /** @param {string} value @returns {MdNode} */ export declare function htmlBlock(value: string): MdNode; /** * @param {(string|null)[]} align * @param {MdNode[]} children * @returns {MdNode} */ export declare function table(align: (string | null)[], children: MdNode[]): MdNode; /** @param {MdNode[]} children @returns {MdNode} */ export declare function tableRow(children: MdNode[]): MdNode; /** @param {MdNode[]} children @returns {MdNode} */ export declare function tableCell(children: MdNode[]): MdNode; /** @param {string} value @returns {MdNode} */ export declare function text(value: string): MdNode; /** @param {MdNode[]} children @returns {MdNode} */ export declare function emphasis(children: MdNode[]): MdNode; /** @param {MdNode[]} children @returns {MdNode} */ export declare function strong(children: MdNode[]): MdNode; /** @param {MdNode[]} children @returns {MdNode} */ export declare function strikethrough(children: MdNode[]): MdNode; /** * @param {string} url * @param {string|null} title * @param {MdNode[]} children * @returns {MdNode} */ export declare function link(url: string, title: string | null, children: MdNode[]): MdNode; /** * A GFM literal autolink (`www.example.com`, `a@b.test`): a `link`, not * a type of its own — every consumer, plugin and schema would otherwise * have to learn a second spelling of the same thing. The `auto` flag is * carried for the ONE consumer that has to tell them apart, the * canonical printer, which prints it back bare (MD-FORMAT.md §4.7). * @param {string} url the resolved destination (scheme inserted) * @param {string} literal the text as the author wrote it * @returns {MdNode} */ export declare function autolink(url: string, literal: string): MdNode; /** * A GFM footnote definition: block content collected out of the flow * and rendered once, at the end, if something cites it. * @param {string} identifier the normalized label (matching key) * @param {string} label the label as written * @param {MdNode[]} children * @returns {MdNode} */ export declare function footnoteDefinition(identifier: string, label: string, children: MdNode[]): MdNode; /** * A GFM footnote reference: the citation mark in the text. * @param {string} identifier the normalized label (matching key) * @param {string} label the label as written * @returns {MdNode} */ export declare function footnoteReference(identifier: string, label: string): MdNode; /** * @param {string} url * @param {string|null} title * @param {string} alt * @returns {MdNode} */ export declare function image(url: string, title: string | null, alt: string): MdNode; /** @param {string} value @returns {MdNode} */ export declare function inlineCode(value: string): MdNode; /** @returns {MdNode} */ export declare function hardBreak(): MdNode; /** @returns {MdNode} */ export declare function softBreak(): MdNode; /** * The generic escape hatch for constructs without a compiled-in plugin * vocabulary (MD-FORMAT §4.4). * @param {string} name * @param {any} data * @param {MdNode[]} [children] * @returns {MdNode} */ export declare function custom(name: string, data: any, children?: MdNode[]): MdNode; /** * Walk an AST (a node or an array of nodes) in document order, calling * `visitor(node, parent, index)` pre-order. Returning `false` from the * visitor skips the node's children. * * @param {MdNode | MdNode[]} root * @param {(node: MdNode, parent: MdNode|null, index: number) => (boolean|void)} visitor */ export declare function walkAst(root: MdNode | MdNode[], visitor: (node: MdNode, parent: MdNode | null, index: number) => (boolean | void)): void; export type MdVisitFn = (node: MdNode, parent: MdNode | null, index: number) => (boolean | void); export type MdVisitSpec = MdVisitFn | { enter?: MdVisitFn; exit?: MdVisitFn; }; /** * @typedef {(node: MdNode, parent: MdNode|null, index: number) => (boolean|void)} MdVisitFn * @typedef {MdVisitFn | { enter?: MdVisitFn, exit?: MdVisitFn }} MdVisitSpec */ /** * Compile a per-type visitor spec into a dispatch table and walk with * it. Handlers are keyed by node type, `'*'` matches every type; a * handler is a function (pre-order) or `{ enter, exit }`. An `enter` * returning `false` skips the children (exit still runs). * * The table is built once per call — pass the same spec object to reuse * the compiled form across documents (a `WeakMap` memo keeps this * allocation-free on repeat visits). * * @param {MdNode | MdNode[]} root * @param {Record} visitors */ export declare function visitAst(root: MdNode | MdNode[], visitors: Record): void; /** * The plain-text content of a node subtree (alt-text derivation, * heading slugs, search indexing). * @param {MdNode | MdNode[]} root * @returns {string} */ export declare function textOf(root: MdNode | MdNode[]): string;