/** * DOCX Module - HTML to DOCX Converter * * Converts an HTML string into DOCX document body content (paragraphs, tables, etc.). * Handles common HTML elements: p, h1-h6, strong, em, a, ul, ol, li, table, img, br, span. * * This is NOT a full HTML rendering engine — it covers the structural elements * that map cleanly to WordprocessingML concepts. * * @example * ```ts * import { htmlToDocxBody } from "excelts/word/html"; * import { Document, toBuffer } from "excelts/word"; * * const body = htmlToDocxBody("

Hello

World

"); * const h = Document.create(); * for (const block of body) { * Document.addBodyContent(h, block); * } * const buffer = await toBuffer(Document.build(h)); * ``` */ import type { BodyContent, ImageDef } from "../../types.js"; /** Options for HTML to DOCX conversion. */ export interface HtmlImportOptions { /** Default font size in half-points (default: 24 = 12pt). */ readonly defaultFontSize?: number; /** Default font family. */ readonly defaultFont?: string; /** Map of CSS class names to inline style strings. Matched classes are merged with element styles. */ readonly classStyles?: Record; } /** * Convert an HTML string into an array of DOCX body content blocks. * * Supported elements: * - Block: p, div, h1-h6, blockquote, pre, hr * - List: ul, ol, li * - Table: table, thead, tbody, tr, th, td (colspan, rowspan, border styles) * - Inline: strong/b, em/i, u, s/strike/del, a, br, span, sub, sup, code * - Images: img (base64 data URLs as InlineImageContent, http(s) as placeholder) * - Page break: div with style="page-break-before: always" or class="page-break" * - CSS inline styles: font-family, font-size, color, background-color, font-weight, * font-style, text-decoration, text-align * * @param html - The HTML string to convert. * @param options - Optional conversion settings. * @returns Array of BodyContent blocks. */ export declare function htmlToDocxBody(html: string, options?: HtmlImportOptions): BodyContent[]; /** Result of {@link htmlToDocx}: body content plus the images it references. */ export interface HtmlToDocxResult { /** Parsed body content blocks. */ readonly body: BodyContent[]; /** * Images decoded from base64 `data:` URLs in the HTML, each with a unique * rId already referenced by the matching image run in `body`. Merge these * into the document model's `images` array so the pictures are embedded as * real media in the package instead of dropped as placeholders. */ readonly images: ImageDef[]; } /** * Convert an HTML string into DOCX body content **and** embedded images. * * Unlike {@link htmlToDocxBody}, this decodes base64 `data:` image URLs into * real {@link ImageDef}s and assigns each a unique rId that the emitted image * runs reference. Merge the returned `images` into your document model so the * pictures are embedded rather than dropped as placeholders. * * @example * ```ts * const { body, images } = htmlToDocx(html); * const doc = Document.create(); * for (const item of body) Document.addContent(doc, item); * const built = Document.build(doc); * const final = { ...built, images: [...(built.images ?? []), ...images] }; * const bytes = await toBuffer(final); * ``` */ export declare function htmlToDocx(html: string, options?: HtmlImportOptions): HtmlToDocxResult;