import * as docx15 from "docx"; import { Document, FileChild, IParagraphStylePropertiesOptions, IPropertiesOptions, IRunStylePropertiesOptions, Packer, Paragraph, ParagraphChild } from "docx"; import { Lexer, MarkedOptions, Token, Tokens } from "marked"; //#region src/extensions/types.d.ts /** * Represents a single footnote. */ type Footnote = { id: number; type: 'footnote'; raw: string; label: string; tokens: Token[]; }; /** * Represents a reference to a footnote. */ type FootnoteRef = { type: 'footnoteRef'; raw: string; id: number; label: string; }; type InlineKatex = { type: 'inlineKatex'; raw: string; displayMode: boolean; text: string; }; type BlockKatex = { type: 'blockKatex'; raw: string; displayMode: boolean; text: string; }; //#endregion //#region src/types.d.ts type MarkdownImageType = 'jpg' | 'png' | 'gif' | 'bmp'; type MarkdownImageItem = { type: MarkdownImageType; data: Buffer | string | Uint8Array | ArrayBuffer; width: number; height: number; }; type MarkdownImageAdapter = (token: Tokens.Image) => Promise; interface MarkdownDocxOptions extends MarkedOptions { imageAdapter?: MarkdownImageAdapter; /** * Math engine configuration * builtin: simple unicode mapping * katex: KaTeX -> MathML -> docx Math */ math?: { engine?: 'builtin' | 'katex'; katexOptions?: Record; /** Prefer constructs that are broadly supported by LibreOffice (e.g., avoid true OMML matrices and n-ary) */ libreOfficeCompat?: boolean; }; /** * do not download image * @default false */ ignoreImage?: boolean; /** * do not parse footnote * @default false */ ignoreFootnote?: boolean; /** * do not parse html * @default false */ ignoreHtml?: boolean; /** * Properties for the document */ document?: Omit; /** * colors theme */ theme?: Partial; } type IBlockToken = Tokens.Space | Tokens.Code | Tokens.Heading | Tokens.Hr | Tokens.Blockquote | Tokens.List | Tokens.HTML | Tokens.Def | Tokens.Table | Tokens.Heading | Tokens.Paragraph | Tokens.Text | Footnote; type IInlineToken = Tokens.Escape | Tokens.Tag | Tokens.Link | Tokens.Em | Tokens.Strong | Tokens.Codespan | Tokens.Br | Tokens.Del | Tokens.Text | Tokens.Image | FootnoteRef | InlineKatex | BlockKatex; type IParagraphToken = Tokens.Paragraph | Tokens.Blockquote | Tokens.Heading; type ITextAttr = { style?: string; bold?: boolean; italics?: boolean; underline?: boolean; strike?: boolean; break?: boolean | number; html?: boolean; link?: boolean; strong?: boolean; em?: boolean; codespan?: boolean; del?: boolean; br?: boolean; }; type IBlockAttr = { style?: string; blockquote?: boolean; list?: { task?: boolean; checked?: boolean; level: number; type?: 'number' | 'bullet'; /** * @link https://github.com/dolanmiu/docx/pull/816 * @link https://github.com/dolanmiu/docx/issues/3037#issuecomment-3164253396 */ instance?: number; }; listNone?: boolean; heading?: number; code?: boolean; align?: 'left' | 'center' | 'right' | null; footnote?: boolean; }; type Writeable = { -readonly [P in keyof T]: T[P] }; type IMarkdownToken = 'space' | 'code' | 'hr' | 'blockquote' | 'html' | 'def' | 'paragraph' | 'text' | 'footnote' | 'listItem' | 'table' | 'tableHeader' | 'tableCell' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'tag' | 'link' | 'strong' | 'em' | 'codespan' | 'del' | 'br'; type IMarkdownStyle = { inline?: boolean; className: string; name?: string; basedOn?: string; next?: string; run?: IRunStylePropertiesOptions; paragraph?: IParagraphStylePropertiesOptions; quickFormat?: boolean; properties?: any; }; type IMarkdownRenderFunction = (render: MarkdownDocx, token: IInlineToken | IBlockToken, attr?: ITextAttr | IBlockAttr) => ParagraphChild | ParagraphChild[] | FileChild | FileChild[] | false | null; type IMarkdownTheme = { heading1: string; heading2: string; heading3: string; heading4: string; heading5: string; heading6: string; link: string; code: string; tag: string; border: string; codespan: string; codeBackground: string; blockquote: string; blockquoteBackground: string; del: string; hr: string; html: string; tableHeaderBackground: string; /** * size of heading fonts */ heading1Size: number; heading2Size: number; heading3Size: number; heading4Size: number; heading5Size: number; heading6Size: number; spaceSize: number; codeSize: number; linkUnderline: boolean; /** * Body typography customization */ bodySize?: number; lineSpacing?: number; }; //#endregion //#region src/MarkdownDocx.d.ts declare class MarkdownDocx { markdown: string; options: MarkdownDocxOptions; static defaultOptions: MarkdownDocxOptions; styles: { colors: IMarkdownTheme; themes: IMarkdownTheme; classes: { readonly Space: "MdSpace"; readonly Code: "MdCode"; readonly Hr: "MdHr"; readonly Blockquote: "MdBlockquote"; readonly Html: "MdHtml"; readonly Def: "MdDef"; readonly Paragraph: "MdParagraph"; readonly Text: "MdText"; readonly Footnote: "MdFootnote"; readonly ListItem: "MdListItem"; readonly Table: "MdTable"; readonly TableHeader: "MdTableHeader"; readonly TableCell: "MdTableCell"; readonly Heading1: "MdHeading1"; readonly Heading2: "MdHeading2"; readonly Heading3: "MdHeading3"; readonly Heading4: "MdHeading4"; readonly Heading5: "MdHeading5"; readonly Heading6: "MdHeading6"; readonly Tag: "MdTag"; readonly Link: "MdLink"; readonly Strong: "MdStrong"; readonly Em: "MdEm"; readonly Codespan: "MdCodespan"; readonly Del: "MdDel"; readonly Br: "MdBr"; }; default: { readonly document?: docx15.IDocumentDefaultsOptions; readonly title?: docx15.IBaseParagraphStyleOptions; readonly heading1?: docx15.IBaseParagraphStyleOptions; readonly heading2?: docx15.IBaseParagraphStyleOptions; readonly heading3?: docx15.IBaseParagraphStyleOptions; readonly heading4?: docx15.IBaseParagraphStyleOptions; readonly heading5?: docx15.IBaseParagraphStyleOptions; readonly heading6?: docx15.IBaseParagraphStyleOptions; readonly strong?: docx15.IBaseParagraphStyleOptions; readonly listParagraph?: docx15.IBaseParagraphStyleOptions; readonly hyperlink?: docx15.IBaseCharacterStyleOptions; readonly footnoteReference?: docx15.IBaseCharacterStyleOptions; readonly footnoteText?: docx15.IBaseParagraphStyleOptions; readonly footnoteTextChar?: docx15.IBaseCharacterStyleOptions; } | undefined; markdown: Record; numbering: docx15.INumberingOptions; }; store: Map; static covert(markdown: string, _options?: MarkdownDocxOptions): Promise; protected _imageStore: Map; private footnotes; constructor(markdown: string, options?: MarkdownDocxOptions); get ignoreImage(): boolean; get ignoreFootnote(): boolean; get ignoreHtml(): boolean; toDocument(options?: Omit): Promise; toSection(): Promise; downloadImageList(tokens: Tokens.Image[]): Promise<(MarkdownImageItem | undefined)[]>; toBlocks(tokens: IBlockToken[], attr?: IBlockAttr): FileChild[]; toTexts(tokens: IInlineToken[], attr?: ITextAttr): ParagraphChild[]; addFootnote(id: number, children: Paragraph[]): void; findImage(token: Tokens.Image): MarkdownImageItem | null; _blockRender: Map; _inlineRender: Map; addBlockRender(blockType: string, renderFn: Function): void; addInlineRender(inlineType: string, renderFn: Function): void; useBlockRender(block: IBlockToken, attr: IBlockAttr): FileChild | FileChild[] | false | null; useInlineRender(token: IInlineToken, attr: ITextAttr): ParagraphChild | ParagraphChild[] | false | null; } //#endregion //#region src/styles/index.d.ts declare const styles: { colors: IMarkdownTheme; themes: IMarkdownTheme; classes: { readonly Space: "MdSpace"; readonly Code: "MdCode"; readonly Hr: "MdHr"; readonly Blockquote: "MdBlockquote"; readonly Html: "MdHtml"; readonly Def: "MdDef"; readonly Paragraph: "MdParagraph"; readonly Text: "MdText"; readonly Footnote: "MdFootnote"; readonly ListItem: "MdListItem"; readonly Table: "MdTable"; readonly TableHeader: "MdTableHeader"; readonly TableCell: "MdTableCell"; readonly Heading1: "MdHeading1"; readonly Heading2: "MdHeading2"; readonly Heading3: "MdHeading3"; readonly Heading4: "MdHeading4"; readonly Heading5: "MdHeading5"; readonly Heading6: "MdHeading6"; readonly Tag: "MdTag"; readonly Link: "MdLink"; readonly Strong: "MdStrong"; readonly Em: "MdEm"; readonly Codespan: "MdCodespan"; readonly Del: "MdDel"; readonly Br: "MdBr"; }; default: { readonly document?: docx15.IDocumentDefaultsOptions; readonly title?: docx15.IBaseParagraphStyleOptions; readonly heading1?: docx15.IBaseParagraphStyleOptions; readonly heading2?: docx15.IBaseParagraphStyleOptions; readonly heading3?: docx15.IBaseParagraphStyleOptions; readonly heading4?: docx15.IBaseParagraphStyleOptions; readonly heading5?: docx15.IBaseParagraphStyleOptions; readonly heading6?: docx15.IBaseParagraphStyleOptions; readonly strong?: docx15.IBaseParagraphStyleOptions; readonly listParagraph?: docx15.IBaseParagraphStyleOptions; readonly hyperlink?: docx15.IBaseCharacterStyleOptions; readonly footnoteReference?: docx15.IBaseCharacterStyleOptions; readonly footnoteText?: docx15.IBaseParagraphStyleOptions; readonly footnoteTextChar?: docx15.IBaseCharacterStyleOptions; } | undefined; markdown: Record; numbering: docx15.INumberingOptions; }; //#endregion //#region src/index.d.ts declare function markdownDocx(markdown: string, options?: MarkdownDocxOptions): Promise; //#endregion export { IBlockAttr, IBlockToken, IInlineToken, IMarkdownRenderFunction, IMarkdownStyle, IMarkdownTheme, IMarkdownToken, IParagraphToken, ITextAttr, MarkdownDocx, MarkdownDocxOptions, MarkdownImageAdapter, MarkdownImageItem, MarkdownImageType, Packer, Writeable, markdownDocx as default, markdownDocx, styles };