/** * DOCX Module - Style Mapping DSL * * A domain-specific language for customizing how DOCX elements are * mapped to HTML output during conversion. Inspired by mammoth.js's * style mapping approach but designed for this project's architecture. * * The DSL allows users to define rules that control the HTML output * for specific Word styles, without modifying the core renderer. * * Syntax examples: * ``` * p[style-name='Heading 1'] => h1.custom-heading * p[style-name='Quote'] => blockquote.pull-quote * r[style-name='Emphasis'] => em.highlight * p[style-name='Code'] => pre > code * table[style-name='GridTable'] => table.data-table * ``` */ /** Target element type in the mapping rule. */ export type MappingSourceType = "p" | "r" | "table" | "image" | "b" | "i" | "u" | "strike"; /** A condition for matching source elements. */ export interface MappingCondition { /** Attribute to match on. */ readonly attribute: "style-name" | "style-id" | "outline-level" | "numbering-level" | "is-bold" | "is-italic"; /** Value to match (exact or regex). */ readonly value: string; /** Use regex matching. */ readonly regex?: boolean; } /** Target HTML element specification. */ export interface MappingTarget { /** HTML tag name. */ readonly tagName: string; /** CSS class(es) to add. */ readonly className?: string; /** Additional HTML attributes. */ readonly attributes?: Readonly>; /** Nested element (for `pre > code` style mappings). */ readonly child?: MappingTarget; /** Whether to preserve separator. */ readonly separator?: string; /** Whether this is a "fresh" mapping (wrap each paragraph separately). */ readonly fresh?: boolean; } /** A single style mapping rule. */ export interface StyleMappingRule { /** Source element type. */ readonly source: MappingSourceType; /** Conditions that must all be satisfied. */ readonly conditions: readonly MappingCondition[]; /** Target HTML output. */ readonly target: MappingTarget; /** Priority (higher = checked first). Default: 0. */ readonly priority?: number; } /** A compiled set of style mapping rules. */ export interface StyleMap { /** All rules, sorted by priority (highest first). */ readonly rules: readonly StyleMappingRule[]; } /** Options for the style mapping parser. */ export interface StyleMapOptions { /** Base rules to include (before user rules). */ readonly base?: StyleMap; /** Whether to include default mappings (Heading → h1-h6, etc.). */ readonly includeDefaults?: boolean; } /** Default style mappings (standard Word styles → semantic HTML). */ export declare const DEFAULT_STYLE_MAP: StyleMap; /** * Parse a style mapping DSL string into a StyleMap. * * @param dsl - The DSL string (one rule per line). * @param options - Parser options. * @returns A compiled StyleMap. * * @example * ```ts * const map = parseStyleMap(` * p[style-name='Heading 1'] => h1.title * p[style-name='Code Block'] => pre > code * r[style-name='Emphasis'] => em.custom-em * `); * ``` */ export declare function parseStyleMap(dsl: string, options?: StyleMapOptions): StyleMap; /** * Create a style map programmatically (without DSL parsing). */ export declare function createStyleMap(rules: readonly StyleMappingRule[]): StyleMap; /** * Merge multiple style maps together. * Later maps take precedence (higher priority) over earlier ones. */ export declare function mergeStyleMaps(...maps: readonly StyleMap[]): StyleMap; /** * Match a source element against the style map and return the target. * * @param map - The style map to match against. * @param source - Source element type. * @param attributes - Attributes of the source element. * @returns The matching target, or undefined if no match. */ export declare function matchStyleMap(map: StyleMap, source: MappingSourceType, attributes: Readonly>): MappingTarget | undefined;