/** * DOCX Module - Markdown to DOCX Converter * * Converts a GFM (GitHub Flavored Markdown) string into DOCX document body content. * Handles common Markdown elements: headings, paragraphs, bold, italic, strikethrough, * code, links, images, lists, tables, blockquotes, horizontal rules, and fenced code blocks. * * @example * ```ts * import { markdownToDocx } from "excelts/word/markdown"; * import { Document, toBuffer } from "excelts/word"; * * const doc = markdownToDocx("# Hello\n\nWorld **bold**"); * const buffer = await toBuffer(doc); * ``` * * @stability experimental */ import type { AbstractNumbering, BodyContent, DocxDocument, FootnoteDef, ImageDef, ImageMediaType, NumberingInstance } from "../../types.js"; /** Options for Markdown to DOCX conversion. */ export interface MarkdownImportOptions { /** Default font family for body text. */ readonly defaultFont?: string; /** Default font size in half-points (default: 24 = 12pt). */ readonly defaultFontSize?: number; /** Code font family (default: "Courier New"). */ readonly codeFont?: string; /** Code font size in half-points (default: 20 = 10pt). */ readonly codeFontSize?: number; /** Custom image resolver — given a URL, return image data or undefined to skip. */ readonly resolveImage?: (url: string, alt: string) => MarkdownImageData | undefined | Promise; } /** Resolved image data for embedding. */ export interface MarkdownImageData { readonly data: Uint8Array; readonly mediaType: ImageMediaType; readonly width?: number; readonly height?: number; /** * Raster (PNG) fallback for vector images. Required by Word for `svg` * images so non-SVG-aware viewers have something to display. When the * media type is `svg` and this is omitted, the packager synthesizes a * transparent placeholder PNG automatically. */ readonly fallbackData?: Uint8Array; } /** * Result of {@link markdownToDocxBody} — the parsed body content plus the * supporting document-level definitions it references. * * Lists, footnotes and images are *not* self-contained: a list paragraph * references a numbering id, a footnote reference run references a * `FootnoteDef`, and an inline image references an `ImageDef`. Splicing the * `body` alone into a host document that lacks these definitions yields * invalid OOXML. Merge the relevant arrays into the host document (or its * builder state) alongside the body. */ export interface MarkdownBodyResult { readonly body: BodyContent[]; readonly abstractNumberings: AbstractNumbering[]; readonly numberingInstances: NumberingInstance[]; readonly footnotes: FootnoteDef[]; readonly images: ImageDef[]; } /** * Convert a Markdown string into a complete DocxDocument. * * Supports the full GFM feature set including inline images (embedded via the * `resolveImage` callback) and footnotes (`[^id]` references with `[^id]: …` * definitions). Because image resolution and document packaging are inherently * asynchronous, this function is async. * * @param markdown - The GFM Markdown string. * @param options - Optional conversion settings. * @returns A Promise resolving to a DocxDocument ready to be packaged. */ export declare function markdownToDocx(markdown: string, options?: MarkdownImportOptions): Promise; /** * Convert a Markdown string into DOCX body content plus the supporting * document-level definitions it references. * * **Caveat — body content is not self-contained.** The returned `body` may * reference: * - **Numbering** (`abstractNumberings` / `numberingInstances`) — used by * bullet / numbered / task lists. * - **Footnotes** (`footnotes`) — referenced by footnote-reference runs. * - **Images** (`images`) — referenced by inline image runs. * - The named `Quote` / `CodeBlock` styles (for block quotes / code blocks). * * Splice the relevant arrays into your host document alongside the body, or * use the higher-level {@link markdownToDocx} which returns a complete * `DocxDocument` with everything populated. * * @param markdown - The GFM Markdown string. * @param options - Optional conversion settings. * @returns A Promise resolving to the body and its supporting definitions. */ export declare function markdownToDocxBody(markdown: string, options?: MarkdownImportOptions): Promise;