@cylixlee/mdocx
Advanced tools
| import * as docx0 from "docx"; | ||
| import { Document, FileChild, IParagraphStylePropertiesOptions, IPropertiesOptions, IRunStylePropertiesOptions, IStylesOptions, 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' | 'svg' | 'webp'; | ||
| type MarkdownImageItem = { | ||
| type: MarkdownImageType; | ||
| data: Buffer | string | Uint8Array | ArrayBuffer; | ||
| width: number; | ||
| height: number; | ||
| }; | ||
| type MarkdownImageAdapter = (token: Tokens.Image, srcBaseDir?: string) => Promise<null | MarkdownImageItem>; | ||
| interface MarkdownDocxOptions extends MarkedOptions { | ||
| imageAdapter?: MarkdownImageAdapter; | ||
| /** | ||
| * Built-in style preset name | ||
| * @default "academic" | ||
| */ | ||
| preset?: string; | ||
| /** | ||
| * Style overrides on top of the preset | ||
| */ | ||
| style?: Partial<IMarkdownStyleConfig>; | ||
| /** | ||
| * Math engine configuration | ||
| * builtin: simple unicode mapping | ||
| * katex: KaTeX -> MathML -> docx Math | ||
| */ | ||
| math?: { | ||
| engine?: 'builtin' | 'katex'; | ||
| katexOptions?: Record<string, any>; | ||
| /** 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; | ||
| /** | ||
| * Base directory for resolving relative image references. | ||
| * When set, relative image paths in the markdown are resolved relative to this directory. | ||
| */ | ||
| baseDir?: string; | ||
| /** | ||
| * Properties for the document | ||
| */ | ||
| document?: Omit<IPropertiesOptions, 'sections'>; | ||
| } | ||
| 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; | ||
| /** | ||
| * When false, override the style's first-line indent with 0. | ||
| * Used for centered standalone images. | ||
| */ | ||
| indentFirstLine?: false; | ||
| }; | ||
| type Writeable<T> = { -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 IFontConfig = string | { | ||
| ascii?: string; | ||
| eastAsia?: string; | ||
| hAnsi?: string; | ||
| cs?: string; | ||
| }; | ||
| interface IBorderConfig { | ||
| style?: string; | ||
| size?: number; | ||
| color?: string; | ||
| space?: number; | ||
| } | ||
| interface IElementStyle { | ||
| font?: IFontConfig; | ||
| size?: number; | ||
| color?: string; | ||
| bold?: boolean; | ||
| italics?: boolean; | ||
| underline?: boolean; | ||
| strike?: boolean; | ||
| spacingBefore?: number; | ||
| spacingAfter?: number; | ||
| lineSpacing?: number; | ||
| alignment?: 'left' | 'center' | 'right' | 'both'; | ||
| indentLeft?: number; | ||
| indentHanging?: number; | ||
| indentFirstLine?: number; | ||
| keepNext?: boolean; | ||
| outlineLevel?: number; | ||
| threeLine?: boolean; | ||
| borderTop?: IBorderConfig; | ||
| borderBottom?: IBorderConfig; | ||
| borderLeft?: IBorderConfig; | ||
| borderRight?: IBorderConfig; | ||
| background?: string; | ||
| } | ||
| interface IMarkdownStyleConfig { | ||
| defaultFont?: IFontConfig; | ||
| defaultSize?: number; | ||
| lineSpacing?: number; | ||
| paragraph?: Partial<IElementStyle>; | ||
| heading1?: Partial<IElementStyle>; | ||
| heading2?: Partial<IElementStyle>; | ||
| heading3?: Partial<IElementStyle>; | ||
| heading4?: Partial<IElementStyle>; | ||
| heading5?: Partial<IElementStyle>; | ||
| heading6?: Partial<IElementStyle>; | ||
| code?: Partial<IElementStyle>; | ||
| codespan?: Partial<IElementStyle>; | ||
| blockquote?: Partial<IElementStyle>; | ||
| link?: Partial<IElementStyle>; | ||
| strong?: Partial<IElementStyle>; | ||
| em?: Partial<IElementStyle>; | ||
| del?: Partial<IElementStyle>; | ||
| hr?: Partial<IElementStyle>; | ||
| listItem?: Partial<IElementStyle>; | ||
| table?: Partial<IElementStyle>; | ||
| tableHeader?: Partial<IElementStyle>; | ||
| tableCell?: Partial<IElementStyle>; | ||
| tag?: Partial<IElementStyle>; | ||
| html?: Partial<IElementStyle>; | ||
| space?: Partial<IElementStyle>; | ||
| footnote?: Partial<IElementStyle>; | ||
| br?: Partial<IElementStyle>; | ||
| } | ||
| //#endregion | ||
| //#region src/styles/styles.d.ts | ||
| declare function createDefaultStyle(config: IMarkdownStyleConfig): IStylesOptions['default']; | ||
| declare function createDocumentStyle(config: IMarkdownStyleConfig): IStylesOptions; | ||
| //#endregion | ||
| //#region src/styles/index.d.ts | ||
| declare const styles: { | ||
| 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"; | ||
| }; | ||
| markdown: Record<IMarkdownToken, IMarkdownStyle>; | ||
| numbering: docx0.INumberingOptions; | ||
| createDefaultStyle: typeof createDefaultStyle; | ||
| createDocumentStyle: typeof createDocumentStyle; | ||
| }; | ||
| //#endregion | ||
| //#region src/MarkdownDocx.d.ts | ||
| declare class MarkdownDocx { | ||
| markdown: string; | ||
| options: MarkdownDocxOptions; | ||
| static defaultOptions: MarkdownDocxOptions; | ||
| styles: { | ||
| 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"; | ||
| }; | ||
| markdown: Record<IMarkdownToken, IMarkdownStyle>; | ||
| numbering: docx0.INumberingOptions; | ||
| createDefaultStyle: typeof createDefaultStyle; | ||
| createDocumentStyle: typeof createDocumentStyle; | ||
| }; | ||
| _styleConfig: IMarkdownStyleConfig | undefined; | ||
| store: Map<Symbol, any>; | ||
| static covert(markdown: string, _options?: MarkdownDocxOptions): Promise<Document>; | ||
| protected _imageStore: Map<string, MarkdownImageItem>; | ||
| private footnotes; | ||
| constructor(markdown: string, options?: MarkdownDocxOptions); | ||
| get ignoreImage(): boolean; | ||
| get ignoreFootnote(): boolean; | ||
| get ignoreHtml(): boolean; | ||
| toDocument(options?: Omit<IPropertiesOptions, 'sections'>): Promise<Document>; | ||
| toSection(): Promise<FileChild[]>; | ||
| 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<string, Function>; | ||
| _inlineRender: Map<string, Function>; | ||
| 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/presets/index.d.ts | ||
| declare const presets: Record<string, IMarkdownStyleConfig>; | ||
| declare function getPreset(name: string): IMarkdownStyleConfig; | ||
| declare function resolveStyleConfig(preset: string | IMarkdownStyleConfig, overrides?: Partial<IMarkdownStyleConfig>): IMarkdownStyleConfig; | ||
| //#endregion | ||
| //#region src/index.d.ts | ||
| declare function markdownDocx(markdown: string, options?: MarkdownDocxOptions): Promise<docx0.Document>; | ||
| //#endregion | ||
| export { IBlockAttr, IBlockToken, IBorderConfig, IElementStyle, IFontConfig, IInlineToken, IMarkdownRenderFunction, IMarkdownStyle, IMarkdownStyleConfig, IMarkdownToken, IParagraphToken, ITextAttr, MarkdownDocx, MarkdownDocxOptions, MarkdownImageAdapter, MarkdownImageItem, MarkdownImageType, Packer, Writeable, markdownDocx as default, markdownDocx, getPreset, presets, resolveStyleConfig, styles }; |
+14
-4
@@ -706,3 +706,4 @@ #!/usr/bin/env node | ||
| } : void 0, | ||
| style: attr.style | ||
| style: attr.style, | ||
| ...attr.indentFirstLine === false ? { indent: { firstLine: 0 } } : {} | ||
| }; | ||
@@ -997,2 +998,5 @@ const children = typeof tokens === "string" ? renderText(render, tokens, {}) : renderTokens(render, tokens, {}); | ||
| //#region src/renders/render-blocks.ts | ||
| function isStandaloneImage(tokens) { | ||
| return !!tokens && tokens.length > 0 && tokens.every((t) => t.type === "image"); | ||
| } | ||
| function renderBlocks(render, blocks, attr = {}) { | ||
@@ -1075,3 +1079,7 @@ const paragraphs = []; | ||
| style: classes.Paragraph, | ||
| ...attr | ||
| ...attr, | ||
| ...isStandaloneImage(block.tokens) ? { | ||
| align: "center", | ||
| indentFirstLine: false | ||
| } : {} | ||
| }); | ||
@@ -1819,2 +1827,4 @@ case "text": | ||
| const { width, height, type } = imagesize(buffer); | ||
| const cappedWidth = Math.min(width, MAX_IMAGE_WIDTH); | ||
| const cappedHeight = width ? Math.round(height * cappedWidth / width) : height; | ||
| const supportType = getImageExtension(src, type); | ||
@@ -1829,4 +1839,4 @@ if (!supportType) return null; | ||
| data: buffer, | ||
| width, | ||
| height | ||
| width: cappedWidth, | ||
| height: cappedHeight | ||
| }; | ||
@@ -1833,0 +1843,0 @@ } catch (error) { |
+14
-4
@@ -733,3 +733,4 @@ Object.defineProperties(exports, { | ||
| } : void 0, | ||
| style: attr.style | ||
| style: attr.style, | ||
| ...attr.indentFirstLine === false ? { indent: { firstLine: 0 } } : {} | ||
| }; | ||
@@ -1024,2 +1025,5 @@ const children = typeof tokens === "string" ? renderText(render, tokens, {}) : renderTokens(render, tokens, {}); | ||
| //#region src/renders/render-blocks.ts | ||
| function isStandaloneImage(tokens) { | ||
| return !!tokens && tokens.length > 0 && tokens.every((t) => t.type === "image"); | ||
| } | ||
| function renderBlocks(render, blocks, attr = {}) { | ||
@@ -1102,3 +1106,7 @@ const paragraphs = []; | ||
| style: classes.Paragraph, | ||
| ...attr | ||
| ...attr, | ||
| ...isStandaloneImage(block.tokens) ? { | ||
| align: "center", | ||
| indentFirstLine: false | ||
| } : {} | ||
| }); | ||
@@ -1846,2 +1854,4 @@ case "text": | ||
| const { width, height, type } = (0, image_size.default)(buffer); | ||
| const cappedWidth = Math.min(width, MAX_IMAGE_WIDTH); | ||
| const cappedHeight = width ? Math.round(height * cappedWidth / width) : height; | ||
| const supportType = getImageExtension(src, type); | ||
@@ -1856,4 +1866,4 @@ if (!supportType) return null; | ||
| data: buffer, | ||
| width, | ||
| height | ||
| width: cappedWidth, | ||
| height: cappedHeight | ||
| }; | ||
@@ -1860,0 +1870,0 @@ } catch (error) { |
+14
-4
@@ -701,3 +701,4 @@ import { AlignmentType, BorderStyle, CheckBox, Document, ExternalHyperlink, FootnoteReferenceRun, HeadingLevel, ImageRun, LevelFormat, Math as Math$1, MathFraction, MathIntegral, MathRadical, MathRun, MathSubScript, MathSubSuperScript, MathSum, MathSuperScript, Packer, Paragraph, Table, TableCell, TableRow, TextRun, UnderlineType, VerticalAlign, WidthType, XmlComponent } from "docx"; | ||
| } : void 0, | ||
| style: attr.style | ||
| style: attr.style, | ||
| ...attr.indentFirstLine === false ? { indent: { firstLine: 0 } } : {} | ||
| }; | ||
@@ -992,2 +993,5 @@ const children = typeof tokens === "string" ? renderText(render, tokens, {}) : renderTokens(render, tokens, {}); | ||
| //#region src/renders/render-blocks.ts | ||
| function isStandaloneImage(tokens) { | ||
| return !!tokens && tokens.length > 0 && tokens.every((t) => t.type === "image"); | ||
| } | ||
| function renderBlocks(render, blocks, attr = {}) { | ||
@@ -1070,3 +1074,7 @@ const paragraphs = []; | ||
| style: classes.Paragraph, | ||
| ...attr | ||
| ...attr, | ||
| ...isStandaloneImage(block.tokens) ? { | ||
| align: "center", | ||
| indentFirstLine: false | ||
| } : {} | ||
| }); | ||
@@ -1814,2 +1822,4 @@ case "text": | ||
| const { width, height, type } = imagesize(buffer); | ||
| const cappedWidth = Math.min(width, MAX_IMAGE_WIDTH); | ||
| const cappedHeight = width ? Math.round(height * cappedWidth / width) : height; | ||
| const supportType = getImageExtension(src, type); | ||
@@ -1824,4 +1834,4 @@ if (!supportType) return null; | ||
| data: buffer, | ||
| width, | ||
| height | ||
| width: cappedWidth, | ||
| height: cappedHeight | ||
| }; | ||
@@ -1828,0 +1838,0 @@ } catch (error) { |
+1
-1
| { | ||
| "name": "@cylixlee/mdocx", | ||
| "version": "0.2.4", | ||
| "version": "0.2.5", | ||
| "description": "Convert Markdown file to DOCX format", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
| import * as docx0 from "docx"; | ||
| import { Document, FileChild, IParagraphStylePropertiesOptions, IPropertiesOptions, IRunStylePropertiesOptions, IStylesOptions, 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' | 'svg' | 'webp'; | ||
| type MarkdownImageItem = { | ||
| type: MarkdownImageType; | ||
| data: Buffer | string | Uint8Array | ArrayBuffer; | ||
| width: number; | ||
| height: number; | ||
| }; | ||
| type MarkdownImageAdapter = (token: Tokens.Image, srcBaseDir?: string) => Promise<null | MarkdownImageItem>; | ||
| interface MarkdownDocxOptions extends MarkedOptions { | ||
| imageAdapter?: MarkdownImageAdapter; | ||
| /** | ||
| * Built-in style preset name | ||
| * @default "academic" | ||
| */ | ||
| preset?: string; | ||
| /** | ||
| * Style overrides on top of the preset | ||
| */ | ||
| style?: Partial<IMarkdownStyleConfig>; | ||
| /** | ||
| * Math engine configuration | ||
| * builtin: simple unicode mapping | ||
| * katex: KaTeX -> MathML -> docx Math | ||
| */ | ||
| math?: { | ||
| engine?: 'builtin' | 'katex'; | ||
| katexOptions?: Record<string, any>; | ||
| /** 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; | ||
| /** | ||
| * Base directory for resolving relative image references. | ||
| * When set, relative image paths in the markdown are resolved relative to this directory. | ||
| */ | ||
| baseDir?: string; | ||
| /** | ||
| * Properties for the document | ||
| */ | ||
| document?: Omit<IPropertiesOptions, 'sections'>; | ||
| } | ||
| 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<T> = { -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 IFontConfig = string | { | ||
| ascii?: string; | ||
| eastAsia?: string; | ||
| hAnsi?: string; | ||
| cs?: string; | ||
| }; | ||
| interface IBorderConfig { | ||
| style?: string; | ||
| size?: number; | ||
| color?: string; | ||
| space?: number; | ||
| } | ||
| interface IElementStyle { | ||
| font?: IFontConfig; | ||
| size?: number; | ||
| color?: string; | ||
| bold?: boolean; | ||
| italics?: boolean; | ||
| underline?: boolean; | ||
| strike?: boolean; | ||
| spacingBefore?: number; | ||
| spacingAfter?: number; | ||
| lineSpacing?: number; | ||
| alignment?: 'left' | 'center' | 'right' | 'both'; | ||
| indentLeft?: number; | ||
| indentHanging?: number; | ||
| indentFirstLine?: number; | ||
| keepNext?: boolean; | ||
| outlineLevel?: number; | ||
| threeLine?: boolean; | ||
| borderTop?: IBorderConfig; | ||
| borderBottom?: IBorderConfig; | ||
| borderLeft?: IBorderConfig; | ||
| borderRight?: IBorderConfig; | ||
| background?: string; | ||
| } | ||
| interface IMarkdownStyleConfig { | ||
| defaultFont?: IFontConfig; | ||
| defaultSize?: number; | ||
| lineSpacing?: number; | ||
| paragraph?: Partial<IElementStyle>; | ||
| heading1?: Partial<IElementStyle>; | ||
| heading2?: Partial<IElementStyle>; | ||
| heading3?: Partial<IElementStyle>; | ||
| heading4?: Partial<IElementStyle>; | ||
| heading5?: Partial<IElementStyle>; | ||
| heading6?: Partial<IElementStyle>; | ||
| code?: Partial<IElementStyle>; | ||
| codespan?: Partial<IElementStyle>; | ||
| blockquote?: Partial<IElementStyle>; | ||
| link?: Partial<IElementStyle>; | ||
| strong?: Partial<IElementStyle>; | ||
| em?: Partial<IElementStyle>; | ||
| del?: Partial<IElementStyle>; | ||
| hr?: Partial<IElementStyle>; | ||
| listItem?: Partial<IElementStyle>; | ||
| table?: Partial<IElementStyle>; | ||
| tableHeader?: Partial<IElementStyle>; | ||
| tableCell?: Partial<IElementStyle>; | ||
| tag?: Partial<IElementStyle>; | ||
| html?: Partial<IElementStyle>; | ||
| space?: Partial<IElementStyle>; | ||
| footnote?: Partial<IElementStyle>; | ||
| br?: Partial<IElementStyle>; | ||
| } | ||
| //#endregion | ||
| //#region src/styles/styles.d.ts | ||
| declare function createDefaultStyle(config: IMarkdownStyleConfig): IStylesOptions['default']; | ||
| declare function createDocumentStyle(config: IMarkdownStyleConfig): IStylesOptions; | ||
| //#endregion | ||
| //#region src/styles/index.d.ts | ||
| declare const styles: { | ||
| 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"; | ||
| }; | ||
| markdown: Record<IMarkdownToken, IMarkdownStyle>; | ||
| numbering: docx0.INumberingOptions; | ||
| createDefaultStyle: typeof createDefaultStyle; | ||
| createDocumentStyle: typeof createDocumentStyle; | ||
| }; | ||
| //#endregion | ||
| //#region src/MarkdownDocx.d.ts | ||
| declare class MarkdownDocx { | ||
| markdown: string; | ||
| options: MarkdownDocxOptions; | ||
| static defaultOptions: MarkdownDocxOptions; | ||
| styles: { | ||
| 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"; | ||
| }; | ||
| markdown: Record<IMarkdownToken, IMarkdownStyle>; | ||
| numbering: docx0.INumberingOptions; | ||
| createDefaultStyle: typeof createDefaultStyle; | ||
| createDocumentStyle: typeof createDocumentStyle; | ||
| }; | ||
| _styleConfig: IMarkdownStyleConfig | undefined; | ||
| store: Map<Symbol, any>; | ||
| static covert(markdown: string, _options?: MarkdownDocxOptions): Promise<Document>; | ||
| protected _imageStore: Map<string, MarkdownImageItem>; | ||
| private footnotes; | ||
| constructor(markdown: string, options?: MarkdownDocxOptions); | ||
| get ignoreImage(): boolean; | ||
| get ignoreFootnote(): boolean; | ||
| get ignoreHtml(): boolean; | ||
| toDocument(options?: Omit<IPropertiesOptions, 'sections'>): Promise<Document>; | ||
| toSection(): Promise<FileChild[]>; | ||
| 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<string, Function>; | ||
| _inlineRender: Map<string, Function>; | ||
| 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/presets/index.d.ts | ||
| declare const presets: Record<string, IMarkdownStyleConfig>; | ||
| declare function getPreset(name: string): IMarkdownStyleConfig; | ||
| declare function resolveStyleConfig(preset: string | IMarkdownStyleConfig, overrides?: Partial<IMarkdownStyleConfig>): IMarkdownStyleConfig; | ||
| //#endregion | ||
| //#region src/index.d.ts | ||
| declare function markdownDocx(markdown: string, options?: MarkdownDocxOptions): Promise<docx0.Document>; | ||
| //#endregion | ||
| export { IBlockAttr, IBlockToken, IBorderConfig, IElementStyle, IFontConfig, IInlineToken, IMarkdownRenderFunction, IMarkdownStyle, IMarkdownStyleConfig, IMarkdownToken, IParagraphToken, ITextAttr, MarkdownDocx, MarkdownDocxOptions, MarkdownImageAdapter, MarkdownImageItem, MarkdownImageType, Packer, Writeable, markdownDocx as default, markdownDocx, getPreset, presets, resolveStyleConfig, styles }; |
166256
0.93%6189
0.57%