/** * The inline text mini-language, parsed into IR nodes. * * Authoring writes `**bold**`, `\n`, `\t` and friends inside a single string. * By the time DocxIR exists none of that is markup any more: it is text runs, * line breaks and tab runs, each carrying resolved formatting. * * This is deliberately a separate module from `compiler.ts`. The mini-language * is the one piece of DOCX authoring with its own grammar, and it is where the * subtle rules live — a decorator pair may straddle a newline, a tab has to * become a real tab run because a tab character inside `` is dropped, and * a no-proof word has to be its own run so the flag can sit on it alone. * * Scope: decorators, line breaks, tabs, no-proof words, `[text](target)` links * and `{PLACEHOLDER}` tokens. Cross-references and note markers are recognised * only so the compiler can refuse them explicitly rather than render them as * the literal characters an author wrote as markup — see * `containsUnsupportedSyntax`. */ import type { DocxIrInline, DocxIrRunFormatting } from './types'; /** * A matcher for the known-words allowlist, or null when there is nothing to * match. * * Each word matches as a whole token — no letter or digit directly either side * — so `Wiseair` does not match inside `Wiseairy`, while internal punctuation * like `json-to-office` matches literally. */ export declare function buildNoProofWordsRegex(noProofWords?: string[]): RegExp | null; /** True when the text carries a `{PLACEHOLDER}` token. */ export declare function containsPlaceholder(text: string): boolean; /** True when the text carries a `[@id]` cross-reference. */ export declare function containsCrossReference(text: string): boolean; /** True when the text carries a `[text](target)` link. */ export declare function containsLink(text: string): boolean; /** * Name the first piece of syntax in `text` this parser cannot lower. * * The compiler calls this before parsing so an unsupported construct is * reported rather than silently rendered as the literal characters an author * wrote as markup. */ export declare function containsUnsupportedSyntax(text: string): string | undefined; export interface ParseInlineOptions { /** Formatting every run starts from. */ base: DocxIrRunFormatting; /** * Lower `[text](target)` into hyperlink nodes. * * Off by default: a component that does not accept links renders the * brackets as the literal characters the author typed, which is what the * pipeline has always done. */ hyperlinks?: boolean; /** * Colour applied to a run only because a decorator made it bold. * * A separate colour for emphasised text is an authoring feature, so it is * resolved here rather than left for a renderer to infer from `bold`. */ boldColor?: { hex: string; }; /** Words to mark `noProof`, each split into a run of its own. */ noProofWords?: string[]; /** * Resolve a `{NAME}` token. Returning nothing leaves it as literal text. * * A placeholder's meaning is document state — the generation date, the page * being drawn — so the compiler supplies it rather than this module knowing * any of it. */ resolvePlaceholder?: (name: string) => PlaceholderResolution | undefined; /** * Resolve a `[^id]` marker to a note. Returning nothing leaves it literal. * * Resolution happens at the leaf, after decorators: a marker inside * `**bold[^n]**` keeps the surrounding emphasis, which splitting earlier * would break by cutting the `**` pair across segments. */ resolveNote?: (id: string) => { id: number; noteKind: 'footnote' | 'endnote'; } | undefined; /** * Resolve a `[@id]` token to a field, or to nothing to leave it literal. * * The target may appear later in the document, so only a pre-pass over the * whole outline can answer this — which is why the compiler supplies it. */ resolveCrossReference?: (id: string, format: CrossReferenceFormat, token: string) => DocxIrInline | undefined; } /** The `\r`-style switches a `[@id:format]` token may ask for. */ export type CrossReferenceFormat = 'relative' | 'no_context' | 'full_context' | 'none'; /** * Parse authored text into inline IR nodes. * * The shape of the output mirrors what the format needs rather than what the * grammar looked like: a decorated span becomes runs with `bold`/`italic` set, * a `\n` becomes a `lineBreak` node, a `\t` becomes a `tab` node. */ export declare function parseInline(text: string, options: ParseInlineOptions): DocxIrInline[]; /** * A placeholder resolved to something concrete. * * `field` is a live field Word recomputes (a page number); `text` is resolved * once, at generation time (a date). An unknown name resolves to nothing and * the token stays as the characters the author typed. */ export type PlaceholderResolution = { kind: 'field'; instruction: string; cachedText?: string; } | { kind: 'text'; text: string; }; /** * Text with no mini-language at all. * * A heading with no decorators and no cross-reference is rendered character for * character: brackets stay brackets, and a newline stays inside the text rather * than breaking the line. Only no-proof words are still split out, because the * flag has to sit on exactly those runs. */ export declare function parseLiteral(text: string, options: ParseInlineOptions): DocxIrInline[]; //# sourceMappingURL=inline.d.ts.map