/** * @file Directives: comment-carried data that a machine derives and a * human reads. * * ```markdown * Jaren is 23.1x faster on the CTS mean. * ``` * * Every markdown renderer on earth drops HTML comments, so GitHub, an * editor preview and npm all show `Jaren is 23.1x faster` — plain, * correct, static text with no runtime and no template syntax leaking * into the prose. A directive-aware consumer reads the marker instead * and can re-derive the value; `bake` writes the fresh value back into * the source, so a re-derivation is a reviewable diff rather than a * silent drift. * * That is the gap this closes for mdx, whose `{$.path}` spelling renders * as literal gibberish anywhere the transform has not run — usable only * in documents nobody reads raw. * * **The layer never interprets the payload.** `fact` puts a derivation * key there, `mdx` puts a query expression; the vocabulary belongs to the * consumer, and this module owns exactly one thing — the marker grammar * and the pairing — so two consumers cannot disagree about what a * directive is. The namespace is the consumer's too, and one consumer * SHOULD claim one: pairing and the orphan report are per-namespace, so a * repository that spells the same idea two ways has two blind spots. * * There are two ways in, because there are two questions: * * - `scanDirectives(doc)` / `replaceDirectives(doc, …)` work on the * AST, which is what a *rendering* consumer has; * - `scanSourceDirectives(text)` works on the source, which is what a * *rewriting* consumer needs. The AST carries no source offsets (it * is plain JSON built for structural sharing, MD-FORMAT §1.1/§6), and * giving it any would change every node's shape and therefore every * content-hash key — so `bake` splices bytes instead, and both * scanners read the same grammar from the same function. */ export type MdNode = import('./ast.js').MdNode; export type AstDirective = { ns: string; key: string; scope: 'block' | 'inline'; path: number[]; open: number; close: number; nodes: MdNode[]; }; export type SourceDirective = { ns: string; key: string; scope: 'block' | 'inline'; start: number; end: number; bodyStart: number; bodyEnd: number; body: string; }; /** * Classify one comment. The single source of truth for what a directive * marker IS — both scanners and every consumer go through here. * @param {string} text the comment, `` included * @returns {{ ns: string, key: string, closing: boolean } | null} */ export declare function parseMarker(text: string): { ns: string; key: string; closing: boolean; } | null; /** * Find every directive in a parsed document. * * A block directive's markers are `html` block nodes with body blocks * between them; an inline directive's are `html` inline nodes inside one * paragraph. Markers are paired within ONE container — an opener in a * blockquote and a closer outside it are two unpaired markers, not one * directive spanning a boundary that does not exist in the tree. * * @param {any} docOrAst an MdDocument, a CompiledMd or an AST array * @param {{ ns?: string }} [options] restrict to one namespace * @returns {{ directives: AstDirective[], diagnostics: string[] }} */ export declare function scanDirectives(docOrAst: any, options?: { ns?: string; }): { directives: AstDirective[]; diagnostics: string[]; }; /** * Replace every directive body, returning a NEW document. * * The transform is pure and preserves reference equality for everything * it does not touch, so the vnode emitter's per-node memo and the view * patcher's `===` fast path are unaffected — the same contract the mdx * pass keeps (MD-FORMAT §6). * * `replace` returns the nodes to put between the markers. Returning * `undefined` leaves the directive alone. * * @param {any} docOrAst * @param {{ ns?: string }} options * @param {(directive: AstDirective) => (MdNode[]|undefined)} replace * @returns {any} the same shape that came in (document or array) */ export declare function replaceDirectives(docOrAst: any, options: { ns?: string; }, replace: (directive: AstDirective) => (MdNode[] | undefined)): any; /** * Find every directive in SOURCE TEXT, with the offsets a rewriter * needs. * * Comments inside fenced code are skipped: a fence showing a directive * as an EXAMPLE is documentation about the layer, not an instance of it, * and rewriting one would corrupt the very docs that explain it. * (Indented code is not skipped — see the package README's note; the * cross-check in `bake` is what catches the difference.) * * @param {string} source * @param {{ ns?: string }} [options] * @returns {{ directives: SourceDirective[], diagnostics: string[] }} */ export declare function scanSourceDirectives(source: string, options?: { ns?: string; }): { directives: SourceDirective[]; diagnostics: string[]; };