/**
* @file AST → @jarenjs/view vnodes, and the hydrating renderer.
*
* The emitter is a prebuilt dispatch table keyed on node type; plugin
* `render` entries shadow the core entries (that is how the highlight
* plugin takes over `code` nodes). Two identity guarantees feed the
* view patcher's O(1) fast paths (VIEW-FORMAT.md §5.1):
*
* - per-node memo: the same AST node reference emits the same vnode
* reference, so unchanged subtrees of a JSLT-transformed document
* patch in O(1);
* - content-hash keys: block vnodes are keyed by a hash of their
* content, so moved blocks reorder instead of rebuilding.
*
* Raw HTML nodes are dropped by default; `options.html: 'text'` shows
* them literally, and `'vnode'` PARSES them through an allow-list
* (`parseHtmlFragment`, or an injected `parseHtml`). The vnode format
* has no unescaped output in any of the three, which is what makes
* dropping the safe default for untrusted Markdown. Link and image URLs are
* filtered on the same principle: a destination whose scheme can execute
* (`javascript:`, `vbscript:`) or stand in for a document
* (`data:text/html`, `file:`) loses its attribute rather than reaching
* the page. The AST keeps the URL verbatim, so `toMarkdown` still
* round-trips what the author wrote — only the vnode is filtered.
*/
export type MdNode = import('./ast.js').MdNode;
export type MdDocument = import('./ast.js').MdDocument;
export type MdVnodeOptions = {
/**
* plugin set (must match the parse set for claimed nodes)
*/
plugins?: any[];
/**
* raw HTML handling (default
* 'skip'): drop it, show it as literal text, or parse it to vnodes
*/
html?: 'skip' | 'text' | 'vnode';
/**
* the parser `html: 'vnode'`
* uses (default `parseHtmlFragment` from `@jarenjs/md/html`) — the
* injection point for a host's own sanitizer. It returns a LIST of
* vnodes (empty or null when nothing survived); an array is always
* read as a list, because a vnode is an array too and the two would
* otherwise be indistinguishable.
*/
parseHtml?: (html: string) => any;
/**
* link/image URL
* filter, replacing the default deny-list; return the URL to emit, or
* `null` to drop the attribute. Supply one only to widen the policy for
* trusted content (a custom scheme, say) — it is the whole guard.
*/
sanitizeUrl?: (url: string) => (string | null);
/**
* give every heading a GitHub-compatible
* `id` so `[see below](#the-section)` lands (default `false`). The
* default is OFF ON PURPOSE and must stay that way: CommonMark
* specifies `
Foo
`, so an id emitted by default would fail
* every heading example in the conformance corpus and make the
* package's published score a lie. A host that wants anchors asks for
* them; the spec path stays honest.
*/
headingIds?: boolean;
/**
* prepended to every heading id and
* anchor href (default `''`). A host rendering markdown it did not
* author into a page it owns sets this — GitHub's own answer is
* `user-content-` — so an author cannot mint an id that collides with
* the host's own DOM.
*/
slugPrefix?: string;
/**
* append a `#` link to each heading
* so a reader can copy a link to the section (default `false`).
* Requires `headingIds`; without ids there is nothing to link to.
*/
headingAnchors?: boolean;
/**
* the accessible name of the
* appended footnotes section (default `'Footnotes'`).
*/
footnotesLabel?: string;
/**
* give each top-level block a content-hash
* `key` (default `true`).
*
* Keys are what let the view patcher REORDER blocks instead of
* rebuilding them, so any caller whose output will be patched needs
* them — and computing one means hashing the block's whole subtree,
* which is around a quarter of this emitter's cost. A caller that
* renders once and throws the tree away (SSR, a string, a snapshot)
* pays that for nothing and should pass `false`.
*
* It is deliberately NOT inferred. A renderer cannot know whether its
* output will be patched, and guessing wrong silently turns O(1)
* reconciliation into a rebuild — a correctness-shaped failure with no
* error message. The default is the safe answer; opting out is a
* statement about the caller, which is why every caller in this
* repository that passes `false` says why.
*/
keyed?: boolean;
};
export type RenderCtx = {
tables: any;
html: 'skip' | 'text' | 'vnode';
options: MdVnodeOptions;
parseHtml: (html: string) => any;
sanitizeUrl: (url: string) => (string | null);
headingIds: boolean;
slugPrefix: string;
headingAnchors: boolean;
slugs: Map;
footnotes: import('./footnotes.js').Footnotes | null;
footnotePrefix: string;
footnotesLabel: string;
hash: (str: string) => string;
counts: Map;
};
/**
* Emit a whole document (or AST array) as one `article.md` vnode with
* content-hash-keyed block children.
*
* @example
* mdToVnode(parseMarkdown('# Hi'))
* // ['article', { class: 'md' }, [['h1', { key: '…' }, 'Hi']]]
*
* @param {any} docOrCompiled MdDocument, CompiledMd or MdNode[]
* @param {MdVnodeOptions} [options]
* @returns {any}
*/
export declare function mdToVnode(docOrCompiled: any, options?: MdVnodeOptions): any;
/**
* Create a renderer over `@jarenjs/view`'s DOM patcher that also runs
* plugin `hydrate` hooks after mount (PLUGINS.md §5). Returns a
* `render(docOrCompiled)` function.
*
* @param {{
* container: any,
* plugins?: any[],
* html?: 'skip'|'text',
* headingIds?: boolean,
* slugPrefix?: string,
* headingAnchors?: boolean,
* document?: any,
* onEvent?: (binding: any, event: any) => void,
* onHydrateError?: (err: any) => void,
* }} options
* @returns {(docOrCompiled: any) => void}
*/
export declare function createMdRenderer(options: {
container: any;
plugins?: any[];
html?: 'skip' | 'text';
headingIds?: boolean;
slugPrefix?: string;
headingAnchors?: boolean;
document?: any;
onEvent?: (binding: any, event: any) => void;
onHydrateError?: (err: any) => void;
}): (docOrCompiled: any) => void;