/** * @file compileMarkdown: parse once, then hand out specialized * closures. * * A CompiledMd is the package's unit of work: the parsed document plus * lazily-built, cached projections (vnode tree, canonical Markdown, * frontmatter externals). Every projection is computed at most once * per compiled document โ€” calling `toVnode()` twice returns the same * reference, which is what the view patcher's `===` fast path wants. */ export type MdNode = import('./ast.js').MdNode; export type MdDocument = import('./ast.js').MdDocument; export type MdParseOptions = import('./parser.js').MdParseOptions; export type MdCompileOptions = MdParseOptions & { retainSource?: boolean; html?: 'skip' | 'text'; headingIds?: boolean; slugPrefix?: string; headingAnchors?: boolean; footnotesLabel?: string; keyed?: boolean; }; export type CompiledMd = { /** * the parsed document */ doc: MdDocument; /** * `doc.ast` */ ast: MdNode[]; /** * `doc.frontmatter` */ frontmatter: any; /** * `doc.meta.hash` */ hash: string; /** * the source text (null when `retainSource: false`) */ source: string | null; /** * the compiled plugin tables (internal contract) */ tables: any; /** * cached vnode projection */ toVnode: () => any; /** * cached canonical Markdown */ toMarkdown: () => string; /** * pre-order walker over the AST */ walk: (visitor: any) => void; /** * compiled per-type visitor */ visit: (visitors: any) => void; /** * frontmatter as JSLT/query externals */ externals: () => Record; }; /** * @typedef {import('./ast.js').MdNode} MdNode * @typedef {import('./ast.js').MdDocument} MdDocument * @typedef {import('./parser.js').MdParseOptions} MdParseOptions */ /** * @typedef {MdParseOptions & { retainSource?: boolean, * html?: 'skip'|'text', headingIds?: boolean, slugPrefix?: string, * headingAnchors?: boolean, footnotesLabel?: string, * keyed?: boolean }} MdCompileOptions */ /** * The compiled closure bundle. * @typedef {object} CompiledMd * @property {MdDocument} doc the parsed document * @property {MdNode[]} ast `doc.ast` * @property {any} frontmatter `doc.frontmatter` * @property {string} hash `doc.meta.hash` * @property {string|null} source the source text (null when `retainSource: false`) * @property {any} tables the compiled plugin tables (internal contract) * @property {() => any} toVnode cached vnode projection * @property {() => string} toMarkdown cached canonical Markdown * @property {(visitor: any) => void} walk pre-order walker over the AST * @property {(visitors: any) => void} visit compiled per-type visitor * @property {() => Record} externals frontmatter as JSLT/query externals */ /** * Compile Markdown source (or an already-parsed MdDocument) into a * closure bundle. * * @example * const md = compileMarkdown('# Hi\n\nSome *text*.'); * md.toVnode(); // ['article', { class: 'md' }, ...] * md.toMarkdown(); // '# Hi\n\nSome *text*.\n' * md.externals(); // {} โ€” no frontmatter * * @param {string | MdDocument} sourceOrDoc * @param {MdCompileOptions} [options] * @returns {CompiledMd} */ export declare function compileMarkdown(sourceOrDoc: string | MdDocument, options?: MdCompileOptions): CompiledMd; /** * Flatten frontmatter into an externals object for the query/JSLT * engines (MD-FORMAT.md ยง3.4). Only a frontmatter *object* contributes * members; the engine-reserved names `root` and `path` are dropped. * @param {any} frontmatter * @returns {Record} */ export declare function frontmatterExternals(frontmatter: any): Record; /** * Emit a `@jarenjs/forms`-consumable structure from a document whose * frontmatter declares a schema (`$schema` object member or `form:` * key). The caller injects the forms module (or the two functions it * needs) โ€” `@jarenjs/md` stays dependency-free: * * @example * import * as forms from '@jarenjs/forms'; * const form = mdToForm(md.doc, forms); * // { schema, fields, data } or null when no schema is declared * * @param {MdDocument} doc * @param {{ buildFormModel: (schema: any) => any, * createInitialData: (fields: any) => any }} forms * @returns {{ schema: any, fields: any, data: any } | null} */ export declare function mdToForm(doc: MdDocument, forms: { buildFormModel: (schema: any) => any; createInitialData: (fields: any) => any; }): { schema: any; fields: any; data: any; } | null;