open-agreements
Version:
Open-source legal template filling CLI and library
45 lines • 2.2 kB
TypeScript
import type { Element } from '@xmldom/xmldom';
import type { ReplacementValue } from './replacement-keys.js';
/**
* Normalize smart/typographic quotes to ASCII equivalents for matching.
* Uses the same canonical quote set as verifier's normalizeText().
* This is a 1-to-1 character mapping so charMap positions remain valid.
*/
export declare function normalizeQuotes(text: string): string;
export interface PatchResult {
outputPath: string;
zeroMatchKeys: string[];
}
/**
* Patch a DOCX document by replacing bracketed placeholders with template tags.
* Uses a char_map algorithm to handle cross-run replacements where Word splits
* placeholder text across multiple XML run elements.
*
* Supports two key syntax types:
* - Simple: "search text" → replaces all occurrences
* - Context: "context > placeholder" → in tables, replaces placeholder in rows
* where label matches; in paragraphs, replaces first placeholder after context
*
* Processing order: context keys first, simple keys last.
* This ensures qualified rules claim their targets before simple rules sweep up the rest.
*/
export interface PatchOptions {
/** Hex color (e.g. "000000") to apply to replacement text. When set, the
* patcher explicitly sets <w:color> on runs that receive replacement text,
* overriding any inherited placeholder styling (e.g. gray). */
replacementColor?: string;
}
export declare function patchDocument(inputPath: string, outputPath: string, replacements: Record<string, ReplacementValue>, options?: PatchOptions): Promise<PatchResult>;
/**
* Get the text content of the first table cell (label cell) in the same row
* as the paragraph. Returns null if the paragraph is not inside a table cell.
*/
export declare function getTableRowContext(para: Element): string | null;
export declare function getRunText(run: Element): string;
/**
* Check if a run is safe to remove when its text is empty.
* Returns true only if all element children are <w:rPr> or <w:t>.
* Returns false if the run contains drawings, fields, breaks, or other non-text elements.
*/
export declare function isRunSafeToRemove(run: Element): boolean;
//# sourceMappingURL=patcher.d.ts.map