🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@cylixlee/mdocx

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cylixlee/mdocx - npm Package Compare versions

Comparing version
0.1.0
to
0.2.0
+131
bin/mcp.mjs
import fs from 'node:fs/promises'
import path from 'node:path'
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
import markdownToDocx, { Packer, presets } from '../dist/index.node.mjs'
function resolveOutputPath(inputPath, outputPath) {
if (outputPath) return outputPath
return inputPath.replace(/\.mdx?$/, '.docx')
}
async function loadConfigFile(configPath) {
const content = await fs.readFile(configPath, 'utf-8')
return JSON.parse(content)
}
export async function start() {
const pkg = JSON.parse(
await fs.readFile(new URL('../package.json', import.meta.url), 'utf-8')
)
const server = new McpServer(
{ name: 'mdocx', version: pkg.version },
{ capabilities: { tools: {} } }
)
server.registerTool(
'convert_markdown_to_docx',
{
description: 'Convert a Markdown file to DOCX format.',
inputSchema: {
type: 'object',
properties: {
inputPath: {
type: 'string',
description: 'Path to the input Markdown file (.md)',
},
outputPath: {
type: 'string',
description: 'Path for the output DOCX file (defaults to input filename with .docx extension)',
},
preset: {
type: 'string',
enum: Object.keys(presets),
description: `Style preset: ${Object.keys(presets).join(', ')} (default: "academic")`,
},
config: {
type: 'string',
description: 'Path to a JSON config file (may include preset, style, ignoreImage, math, etc.)',
},
},
required: ['inputPath'],
},
},
async (args) => {
const { inputPath, outputPath, preset, config: configPath } = args
const resolvedOutput = resolveOutputPath(inputPath, outputPath)
const ext = path.extname(resolvedOutput)
if (ext && ext.toLowerCase() !== '.docx') {
return {
content: [{ type: 'text', text: `Output file must be a .docx file, but got ${ext}` }],
isError: true,
}
}
const options = {}
if (configPath) {
try {
const configOptions = await loadConfigFile(configPath)
Object.assign(options, configOptions)
} catch (err) {
return {
content: [{ type: 'text', text: `Failed to load config file "${configPath}": ${err.message}` }],
isError: true,
}
}
}
if (preset) {
options.preset = preset
}
let content
try {
content = await fs.readFile(inputPath, 'utf-8')
} catch (err) {
return {
content: [{ type: 'text', text: `Failed to read input file "${inputPath}": ${err.message}` }],
isError: true,
}
}
if (!content) {
return {
content: [{ type: 'text', text: `Input file "${inputPath}" is empty` }],
isError: true,
}
}
let docx
try {
docx = await markdownToDocx(content, options)
} catch (err) {
return {
content: [{ type: 'text', text: `Conversion failed: ${err.message}` }],
isError: true,
}
}
const buffer = Buffer.from(await Packer.toBuffer(docx))
await fs.writeFile(resolvedOutput, buffer)
return {
content: [{ type: 'text', text: `DOCX file created: ${resolvedOutput}` }],
}
}
)
const transport = new StdioServerTransport()
process.on('SIGINT', () => {
server.close().then(() => process.exit(0))
})
process.on('SIGTERM', () => {
server.close().then(() => process.exit(0))
})
await server.connect(transport)
}
import * as docx1 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) => 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;
/**
* 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: docx1.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: docx1.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<docx1.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 };
+8
-0

@@ -28,2 +28,10 @@ #!/usr/bin/env node

program
.command('mcp')
.description('Start MCP server (stdio transport)')
.action(async () => {
const { start } = await import('./mcp.mjs')
await start()
})
program
.action(doCommand)

@@ -30,0 +38,0 @@

+318
-352

@@ -1,3 +0,6 @@

Object.defineProperty(exports, '__esModule', { value: true });
//#region rolldown:runtime
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
//#region \0rolldown/runtime.js
var __create = Object.create;

@@ -23,21 +26,16 @@ var __defProp = Object.defineProperty;

}) : target, mod));
//#endregion
let docx = require("docx");
docx = __toESM(docx);
let katex = require("katex");
katex = __toESM(katex);
katex = __toESM(katex, 1);
let fast_xml_parser = require("fast-xml-parser");
fast_xml_parser = __toESM(fast_xml_parser);
let marked = require("marked");
marked = __toESM(marked);
let image_size = require("image-size");
image_size = __toESM(image_size);
image_size = __toESM(image_size, 1);
let node_fs_promises = require("node:fs/promises");
node_fs_promises = __toESM(node_fs_promises);
node_fs_promises = __toESM(node_fs_promises, 1);
let node_http = require("node:http");
node_http = __toESM(node_http);
node_http = __toESM(node_http, 1);
let node_https = require("node:https");
node_https = __toESM(node_https);
node_https = __toESM(node_https, 1);
//#region src/styles/classes.ts

@@ -72,3 +70,2 @@ const classes = {

};
//#endregion

@@ -338,3 +335,2 @@ //#region src/styles/markdown.ts

const markdown = createMarkdownStyle({});
//#endregion

@@ -381,3 +377,2 @@ //#region src/styles/numbering.ts

}
//#endregion

@@ -419,3 +414,3 @@ //#region src/styles/styles.ts

const keys = Object.keys(markdownTheme);
const styles$1 = { ...createDefaultStyle(config) };
const styles = { ...createDefaultStyle(config) };
for (const key of keys) {

@@ -442,4 +437,4 @@ const style = markdownTheme[key];

});
if (key in styles$1) styles$1[key] = {
...styles$1[key],
if (key in styles) styles[key] = {
...styles[key],
...style

@@ -449,3 +444,3 @@ };

return {
default: styles$1,
default: styles,
paragraphStyles,

@@ -455,3 +450,2 @@ characterStyles

}
//#endregion

@@ -466,3 +460,2 @@ //#region src/styles/index.ts

};
//#endregion

@@ -495,3 +488,2 @@ //#region src/renders/render-list.ts

}
//#endregion

@@ -580,3 +572,2 @@ //#region src/utils.ts

}
//#endregion

@@ -597,3 +588,2 @@ //#region src/renders/render-checkbox.ts

}
//#endregion

@@ -626,3 +616,2 @@ //#region src/renders/render-text.ts

}
//#endregion

@@ -677,3 +666,2 @@ //#region src/renders/render-image.ts

}
//#endregion

@@ -741,3 +729,2 @@ //#region src/renders/render-tokens.ts

}
//#endregion

@@ -767,3 +754,2 @@ //#region src/renders/render-paragraph.ts

}
//#endregion

@@ -836,3 +822,2 @@ //#region src/renders/render-table.ts

}
//#endregion

@@ -1050,3 +1035,2 @@ //#region src/extensions/mathml-to-docx.ts

}
//#endregion

@@ -1142,3 +1126,2 @@ //#region src/renders/render-blocks.ts

}
//#endregion

@@ -1214,3 +1197,2 @@ //#region src/extensions/footnote.ts

}
//#endregion

@@ -1334,4 +1316,4 @@ //#region src/extensions/latex.ts

*/
function parseLatexToText(latex$1) {
let text = latex$1;
function parseLatexToText(latex) {
let text = latex;
for (const [macro, symbol] of macroMap.entries()) {

@@ -1385,3 +1367,2 @@ const regex = new RegExp(`\\\\${macro}(?![a-zA-Z])`, "g");

}
//#endregion

@@ -1404,3 +1385,2 @@ //#region src/extensions/index.ts

}
//#endregion

@@ -1411,332 +1391,323 @@ //#region src/tokenize.ts

}
//#endregion
//#region src/presets/academic.ts
const academic = {
defaultFont: {
ascii: "Times New Roman",
eastAsia: "宋体"
},
defaultSize: 12,
lineSpacing: 1.5,
strong: {
font: {
//#region src/presets/index.ts
const presets = {
academic: {
defaultFont: {
ascii: "Times New Roman",
eastAsia: "黑体"
eastAsia: "宋体"
},
bold: false
},
em: { italics: true },
heading1: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
defaultSize: 12,
lineSpacing: 1.5,
strong: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
bold: false
},
size: 22,
bold: true,
spacingBefore: 24,
spacingAfter: 12
},
heading2: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
em: { italics: true },
heading1: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
size: 22,
bold: true,
spacingBefore: 24,
spacingAfter: 12
},
size: 16,
bold: true,
spacingBefore: 20,
spacingAfter: 10
},
heading3: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
heading2: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
size: 16,
bold: true,
spacingBefore: 20,
spacingAfter: 10
},
size: 14,
bold: true,
spacingBefore: 16,
spacingAfter: 8
},
heading4: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
heading3: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
size: 14,
bold: true,
spacingBefore: 16,
spacingAfter: 8
},
size: 12,
bold: true,
spacingBefore: 14,
spacingAfter: 6
},
heading5: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
heading4: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
size: 12,
bold: true,
spacingBefore: 14,
spacingAfter: 6
},
size: 12,
bold: true,
spacingBefore: 12,
spacingAfter: 6
},
heading6: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
heading5: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
size: 12,
bold: true,
spacingBefore: 12,
spacingAfter: 6
},
size: 12,
bold: true,
spacingBefore: 12,
spacingAfter: 6
},
paragraph: {
spacingBefore: 6,
spacingAfter: 6,
indentFirstLine: 480
},
code: {
font: "Courier New",
size: 11,
background: "f6f6f7",
borderTop: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
heading6: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
size: 12,
bold: true,
spacingBefore: 12,
spacingAfter: 6
},
borderBottom: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
paragraph: {
spacingBefore: 6,
spacingAfter: 6,
indentFirstLine: 480
},
borderLeft: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
code: {
font: "Courier New",
size: 11,
background: "f6f6f7",
borderTop: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
},
borderBottom: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
},
borderLeft: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
},
borderRight: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
},
spacingBefore: 10,
spacingAfter: 10
},
borderRight: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
},
spacingBefore: 10,
spacingAfter: 10
},
codespan: { font: "Courier New" },
blockquote: {
italics: true,
color: "666666",
background: "F9F9F9",
borderLeft: {
style: "single",
size: 20,
codespan: { font: "Courier New" },
blockquote: {
italics: true,
color: "666666",
space: 12
background: "F9F9F9",
borderLeft: {
style: "single",
size: 20,
color: "666666",
space: 12
},
indentLeft: 360,
spacingBefore: 10,
spacingAfter: 10
},
indentLeft: 360,
spacingBefore: 10,
spacingAfter: 10
},
hr: {
borderBottom: {
style: "single",
size: 1,
color: "D9D9D9",
space: 1
hr: {
borderBottom: {
style: "single",
size: 1,
color: "D9D9D9",
space: 1
},
spacingBefore: 12,
spacingAfter: 12
},
spacingBefore: 12,
spacingAfter: 12
},
link: {
color: "0563C1",
underline: true
},
del: {
strike: true,
color: "FF0000"
},
tableHeader: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
link: {
color: "0563C1",
underline: true
},
bold: false
},
table: {
threeLine: true,
spacingBefore: 3,
spacingAfter: 3
},
listItem: {
indentLeft: 720,
indentHanging: 360,
spacingBefore: 3,
spacingAfter: 3
},
tag: {
font: "Courier New",
color: "ED7D31"
},
html: {
font: "Courier New",
color: "4472C4"
},
footnote: { bold: false },
space: {
spacingBefore: 0,
spacingAfter: 0
}
};
//#endregion
//#region src/presets/minimal.ts
const minimal = {
defaultFont: "Calibri",
defaultSize: 11,
lineSpacing: 1.15,
strong: { bold: true },
em: { italics: true },
heading1: {
size: 20,
bold: true,
spacingBefore: 20,
spacingAfter: 10
},
heading2: {
size: 16,
bold: true,
spacingBefore: 16,
spacingAfter: 8
},
heading3: {
size: 14,
bold: true,
spacingBefore: 12,
spacingAfter: 6
},
heading4: {
size: 12,
bold: true,
spacingBefore: 10,
spacingAfter: 4
},
heading5: {
size: 11,
bold: true,
italics: true,
spacingBefore: 8,
spacingAfter: 4
},
heading6: {
size: 11,
italics: true,
spacingBefore: 8,
spacingAfter: 4
},
paragraph: {
spacingBefore: 6,
spacingAfter: 6
},
code: {
font: "Consolas",
size: 10,
background: "F5F5F5",
borderTop: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
del: {
strike: true,
color: "FF0000"
},
borderBottom: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
tableHeader: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
bold: false
},
borderLeft: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
table: {
threeLine: true,
spacingBefore: 3,
spacingAfter: 3
},
borderRight: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
listItem: {
indentLeft: 720,
indentHanging: 360,
spacingBefore: 3,
spacingAfter: 3
},
spacingBefore: 8,
spacingAfter: 8
tag: {
font: "Courier New",
color: "ED7D31"
},
html: {
font: "Courier New",
color: "4472C4"
},
footnote: { bold: false },
space: {
spacingBefore: 0,
spacingAfter: 0
}
},
codespan: {
font: "Consolas",
color: "D63384"
},
blockquote: {
italics: true,
color: "6B7280",
borderLeft: {
style: "single",
minimal: {
defaultFont: "Calibri",
defaultSize: 11,
lineSpacing: 1.15,
strong: { bold: true },
em: { italics: true },
heading1: {
size: 20,
bold: true,
spacingBefore: 20,
spacingAfter: 10
},
heading2: {
size: 16,
color: "D1D5DB",
space: 10
bold: true,
spacingBefore: 16,
spacingAfter: 8
},
indentLeft: 360,
spacingBefore: 8,
spacingAfter: 8
},
hr: {
borderBottom: {
style: "single",
size: 1,
color: "E5E7EB",
space: 1
heading3: {
size: 14,
bold: true,
spacingBefore: 12,
spacingAfter: 6
},
spacingBefore: 10,
spacingAfter: 10
},
link: {
color: "2563EB",
underline: true
},
del: {
strike: true,
color: "DC2626"
},
tableHeader: {
background: "F3F4F6",
bold: true
},
table: {
spacingBefore: 3,
spacingAfter: 3
},
listItem: {
indentLeft: 720,
indentHanging: 360,
spacingBefore: 3,
spacingAfter: 3
},
tag: {
font: "Consolas",
color: "059669"
},
html: {
font: "Consolas",
color: "7C3AED"
},
footnote: { bold: false },
space: {
spacingBefore: 0,
spacingAfter: 0
heading4: {
size: 12,
bold: true,
spacingBefore: 10,
spacingAfter: 4
},
heading5: {
size: 11,
bold: true,
italics: true,
spacingBefore: 8,
spacingAfter: 4
},
heading6: {
size: 11,
italics: true,
spacingBefore: 8,
spacingAfter: 4
},
paragraph: {
spacingBefore: 6,
spacingAfter: 6
},
code: {
font: "Consolas",
size: 10,
background: "F5F5F5",
borderTop: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
},
borderBottom: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
},
borderLeft: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
},
borderRight: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
},
spacingBefore: 8,
spacingAfter: 8
},
codespan: {
font: "Consolas",
color: "D63384"
},
blockquote: {
italics: true,
color: "6B7280",
borderLeft: {
style: "single",
size: 16,
color: "D1D5DB",
space: 10
},
indentLeft: 360,
spacingBefore: 8,
spacingAfter: 8
},
hr: {
borderBottom: {
style: "single",
size: 1,
color: "E5E7EB",
space: 1
},
spacingBefore: 10,
spacingAfter: 10
},
link: {
color: "2563EB",
underline: true
},
del: {
strike: true,
color: "DC2626"
},
tableHeader: {
background: "F3F4F6",
bold: true
},
table: {
spacingBefore: 3,
spacingAfter: 3
},
listItem: {
indentLeft: 720,
indentHanging: 360,
spacingBefore: 3,
spacingAfter: 3
},
tag: {
font: "Consolas",
color: "059669"
},
html: {
font: "Consolas",
color: "7C3AED"
},
footnote: { bold: false },
space: {
spacingBefore: 0,
spacingAfter: 0
}
}
};
//#endregion
//#region src/presets/index.ts
const presets = {
academic,
minimal
};
function getPreset(name) {

@@ -1765,3 +1736,2 @@ const preset = presets[name];

}
//#endregion

@@ -1777,7 +1747,7 @@ //#region src/MarkdownDocx.ts

}
static covert(markdown$1, _options = {}) {
return new MarkdownDocx(markdown$1, _options).toDocument();
static covert(markdown, _options = {}) {
return new MarkdownDocx(markdown, _options).toDocument();
}
constructor(markdown$1, options = {}) {
this.markdown = markdown$1;
constructor(markdown, options = {}) {
this.markdown = markdown;
this.options = options;

@@ -1872,9 +1842,7 @@ this.styles = styles;

};
//#endregion
//#region src/index.ts
function markdownDocx(markdown$1, options = {}) {
return MarkdownDocx.covert(markdown$1, options);
function markdownDocx(markdown, options = {}) {
return MarkdownDocx.covert(markdown, options);
}
//#endregion

@@ -1955,7 +1923,5 @@ //#region src/adapters/nodejs.ts

}
//#endregion
//#region src/entry-node.ts
MarkdownDocx.defaultOptions.imageAdapter = downloadImage;
//#endregion

@@ -1969,2 +1935,2 @@ exports.MarkdownDocx = MarkdownDocx;

exports.resolveStyleConfig = resolveStyleConfig;
exports.styles = styles;
exports.styles = styles;

@@ -9,3 +9,2 @@ 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";

import https from "node:https";
//#region src/styles/classes.ts

@@ -40,3 +39,2 @@ const classes = {

};
//#endregion

@@ -306,3 +304,2 @@ //#region src/styles/markdown.ts

const markdown = createMarkdownStyle({});
//#endregion

@@ -349,3 +346,2 @@ //#region src/styles/numbering.ts

}
//#endregion

@@ -387,3 +383,3 @@ //#region src/styles/styles.ts

const keys = Object.keys(markdownTheme);
const styles$1 = { ...createDefaultStyle(config) };
const styles = { ...createDefaultStyle(config) };
for (const key of keys) {

@@ -410,4 +406,4 @@ const style = markdownTheme[key];

});
if (key in styles$1) styles$1[key] = {
...styles$1[key],
if (key in styles) styles[key] = {
...styles[key],
...style

@@ -417,3 +413,3 @@ };

return {
default: styles$1,
default: styles,
paragraphStyles,

@@ -423,3 +419,2 @@ characterStyles

}
//#endregion

@@ -434,3 +429,2 @@ //#region src/styles/index.ts

};
//#endregion

@@ -463,3 +457,2 @@ //#region src/renders/render-list.ts

}
//#endregion

@@ -548,3 +541,2 @@ //#region src/utils.ts

}
//#endregion

@@ -565,3 +557,2 @@ //#region src/renders/render-checkbox.ts

}
//#endregion

@@ -594,3 +585,2 @@ //#region src/renders/render-text.ts

}
//#endregion

@@ -645,3 +635,2 @@ //#region src/renders/render-image.ts

}
//#endregion

@@ -709,3 +698,2 @@ //#region src/renders/render-tokens.ts

}
//#endregion

@@ -735,3 +723,2 @@ //#region src/renders/render-paragraph.ts

}
//#endregion

@@ -804,3 +791,2 @@ //#region src/renders/render-table.ts

}
//#endregion

@@ -1018,3 +1004,2 @@ //#region src/extensions/mathml-to-docx.ts

}
//#endregion

@@ -1110,3 +1095,2 @@ //#region src/renders/render-blocks.ts

}
//#endregion

@@ -1182,3 +1166,2 @@ //#region src/extensions/footnote.ts

}
//#endregion

@@ -1302,4 +1285,4 @@ //#region src/extensions/latex.ts

*/
function parseLatexToText(latex$1) {
let text = latex$1;
function parseLatexToText(latex) {
let text = latex;
for (const [macro, symbol] of macroMap.entries()) {

@@ -1353,3 +1336,2 @@ const regex = new RegExp(`\\\\${macro}(?![a-zA-Z])`, "g");

}
//#endregion

@@ -1372,3 +1354,2 @@ //#region src/extensions/index.ts

}
//#endregion

@@ -1379,332 +1360,323 @@ //#region src/tokenize.ts

}
//#endregion
//#region src/presets/academic.ts
const academic = {
defaultFont: {
ascii: "Times New Roman",
eastAsia: "宋体"
},
defaultSize: 12,
lineSpacing: 1.5,
strong: {
font: {
//#region src/presets/index.ts
const presets = {
academic: {
defaultFont: {
ascii: "Times New Roman",
eastAsia: "黑体"
eastAsia: "宋体"
},
bold: false
},
em: { italics: true },
heading1: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
defaultSize: 12,
lineSpacing: 1.5,
strong: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
bold: false
},
size: 22,
bold: true,
spacingBefore: 24,
spacingAfter: 12
},
heading2: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
em: { italics: true },
heading1: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
size: 22,
bold: true,
spacingBefore: 24,
spacingAfter: 12
},
size: 16,
bold: true,
spacingBefore: 20,
spacingAfter: 10
},
heading3: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
heading2: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
size: 16,
bold: true,
spacingBefore: 20,
spacingAfter: 10
},
size: 14,
bold: true,
spacingBefore: 16,
spacingAfter: 8
},
heading4: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
heading3: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
size: 14,
bold: true,
spacingBefore: 16,
spacingAfter: 8
},
size: 12,
bold: true,
spacingBefore: 14,
spacingAfter: 6
},
heading5: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
heading4: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
size: 12,
bold: true,
spacingBefore: 14,
spacingAfter: 6
},
size: 12,
bold: true,
spacingBefore: 12,
spacingAfter: 6
},
heading6: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
heading5: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
size: 12,
bold: true,
spacingBefore: 12,
spacingAfter: 6
},
size: 12,
bold: true,
spacingBefore: 12,
spacingAfter: 6
},
paragraph: {
spacingBefore: 6,
spacingAfter: 6,
indentFirstLine: 480
},
code: {
font: "Courier New",
size: 11,
background: "f6f6f7",
borderTop: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
heading6: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
size: 12,
bold: true,
spacingBefore: 12,
spacingAfter: 6
},
borderBottom: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
paragraph: {
spacingBefore: 6,
spacingAfter: 6,
indentFirstLine: 480
},
borderLeft: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
code: {
font: "Courier New",
size: 11,
background: "f6f6f7",
borderTop: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
},
borderBottom: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
},
borderLeft: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
},
borderRight: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
},
spacingBefore: 10,
spacingAfter: 10
},
borderRight: {
style: "single",
size: 1,
color: "A5A5A5",
space: 8
},
spacingBefore: 10,
spacingAfter: 10
},
codespan: { font: "Courier New" },
blockquote: {
italics: true,
color: "666666",
background: "F9F9F9",
borderLeft: {
style: "single",
size: 20,
codespan: { font: "Courier New" },
blockquote: {
italics: true,
color: "666666",
space: 12
background: "F9F9F9",
borderLeft: {
style: "single",
size: 20,
color: "666666",
space: 12
},
indentLeft: 360,
spacingBefore: 10,
spacingAfter: 10
},
indentLeft: 360,
spacingBefore: 10,
spacingAfter: 10
},
hr: {
borderBottom: {
style: "single",
size: 1,
color: "D9D9D9",
space: 1
hr: {
borderBottom: {
style: "single",
size: 1,
color: "D9D9D9",
space: 1
},
spacingBefore: 12,
spacingAfter: 12
},
spacingBefore: 12,
spacingAfter: 12
},
link: {
color: "0563C1",
underline: true
},
del: {
strike: true,
color: "FF0000"
},
tableHeader: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
link: {
color: "0563C1",
underline: true
},
bold: false
},
table: {
threeLine: true,
spacingBefore: 3,
spacingAfter: 3
},
listItem: {
indentLeft: 720,
indentHanging: 360,
spacingBefore: 3,
spacingAfter: 3
},
tag: {
font: "Courier New",
color: "ED7D31"
},
html: {
font: "Courier New",
color: "4472C4"
},
footnote: { bold: false },
space: {
spacingBefore: 0,
spacingAfter: 0
}
};
//#endregion
//#region src/presets/minimal.ts
const minimal = {
defaultFont: "Calibri",
defaultSize: 11,
lineSpacing: 1.15,
strong: { bold: true },
em: { italics: true },
heading1: {
size: 20,
bold: true,
spacingBefore: 20,
spacingAfter: 10
},
heading2: {
size: 16,
bold: true,
spacingBefore: 16,
spacingAfter: 8
},
heading3: {
size: 14,
bold: true,
spacingBefore: 12,
spacingAfter: 6
},
heading4: {
size: 12,
bold: true,
spacingBefore: 10,
spacingAfter: 4
},
heading5: {
size: 11,
bold: true,
italics: true,
spacingBefore: 8,
spacingAfter: 4
},
heading6: {
size: 11,
italics: true,
spacingBefore: 8,
spacingAfter: 4
},
paragraph: {
spacingBefore: 6,
spacingAfter: 6
},
code: {
font: "Consolas",
size: 10,
background: "F5F5F5",
borderTop: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
del: {
strike: true,
color: "FF0000"
},
borderBottom: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
tableHeader: {
font: {
ascii: "Times New Roman",
eastAsia: "黑体"
},
bold: false
},
borderLeft: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
table: {
threeLine: true,
spacingBefore: 3,
spacingAfter: 3
},
borderRight: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
listItem: {
indentLeft: 720,
indentHanging: 360,
spacingBefore: 3,
spacingAfter: 3
},
spacingBefore: 8,
spacingAfter: 8
tag: {
font: "Courier New",
color: "ED7D31"
},
html: {
font: "Courier New",
color: "4472C4"
},
footnote: { bold: false },
space: {
spacingBefore: 0,
spacingAfter: 0
}
},
codespan: {
font: "Consolas",
color: "D63384"
},
blockquote: {
italics: true,
color: "6B7280",
borderLeft: {
style: "single",
minimal: {
defaultFont: "Calibri",
defaultSize: 11,
lineSpacing: 1.15,
strong: { bold: true },
em: { italics: true },
heading1: {
size: 20,
bold: true,
spacingBefore: 20,
spacingAfter: 10
},
heading2: {
size: 16,
color: "D1D5DB",
space: 10
bold: true,
spacingBefore: 16,
spacingAfter: 8
},
indentLeft: 360,
spacingBefore: 8,
spacingAfter: 8
},
hr: {
borderBottom: {
style: "single",
size: 1,
color: "E5E7EB",
space: 1
heading3: {
size: 14,
bold: true,
spacingBefore: 12,
spacingAfter: 6
},
spacingBefore: 10,
spacingAfter: 10
},
link: {
color: "2563EB",
underline: true
},
del: {
strike: true,
color: "DC2626"
},
tableHeader: {
background: "F3F4F6",
bold: true
},
table: {
spacingBefore: 3,
spacingAfter: 3
},
listItem: {
indentLeft: 720,
indentHanging: 360,
spacingBefore: 3,
spacingAfter: 3
},
tag: {
font: "Consolas",
color: "059669"
},
html: {
font: "Consolas",
color: "7C3AED"
},
footnote: { bold: false },
space: {
spacingBefore: 0,
spacingAfter: 0
heading4: {
size: 12,
bold: true,
spacingBefore: 10,
spacingAfter: 4
},
heading5: {
size: 11,
bold: true,
italics: true,
spacingBefore: 8,
spacingAfter: 4
},
heading6: {
size: 11,
italics: true,
spacingBefore: 8,
spacingAfter: 4
},
paragraph: {
spacingBefore: 6,
spacingAfter: 6
},
code: {
font: "Consolas",
size: 10,
background: "F5F5F5",
borderTop: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
},
borderBottom: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
},
borderLeft: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
},
borderRight: {
style: "single",
size: 1,
color: "D4D4D4",
space: 6
},
spacingBefore: 8,
spacingAfter: 8
},
codespan: {
font: "Consolas",
color: "D63384"
},
blockquote: {
italics: true,
color: "6B7280",
borderLeft: {
style: "single",
size: 16,
color: "D1D5DB",
space: 10
},
indentLeft: 360,
spacingBefore: 8,
spacingAfter: 8
},
hr: {
borderBottom: {
style: "single",
size: 1,
color: "E5E7EB",
space: 1
},
spacingBefore: 10,
spacingAfter: 10
},
link: {
color: "2563EB",
underline: true
},
del: {
strike: true,
color: "DC2626"
},
tableHeader: {
background: "F3F4F6",
bold: true
},
table: {
spacingBefore: 3,
spacingAfter: 3
},
listItem: {
indentLeft: 720,
indentHanging: 360,
spacingBefore: 3,
spacingAfter: 3
},
tag: {
font: "Consolas",
color: "059669"
},
html: {
font: "Consolas",
color: "7C3AED"
},
footnote: { bold: false },
space: {
spacingBefore: 0,
spacingAfter: 0
}
}
};
//#endregion
//#region src/presets/index.ts
const presets = {
academic,
minimal
};
function getPreset(name) {

@@ -1733,3 +1705,2 @@ const preset = presets[name];

}
//#endregion

@@ -1745,7 +1716,7 @@ //#region src/MarkdownDocx.ts

}
static covert(markdown$1, _options = {}) {
return new MarkdownDocx(markdown$1, _options).toDocument();
static covert(markdown, _options = {}) {
return new MarkdownDocx(markdown, _options).toDocument();
}
constructor(markdown$1, options = {}) {
this.markdown = markdown$1;
constructor(markdown, options = {}) {
this.markdown = markdown;
this.options = options;

@@ -1840,9 +1811,7 @@ this.styles = styles;

};
//#endregion
//#region src/index.ts
function markdownDocx(markdown$1, options = {}) {
return MarkdownDocx.covert(markdown$1, options);
function markdownDocx(markdown, options = {}) {
return MarkdownDocx.covert(markdown, options);
}
//#endregion

@@ -1923,8 +1892,6 @@ //#region src/adapters/nodejs.ts

}
//#endregion
//#region src/entry-node.ts
MarkdownDocx.defaultOptions.imageAdapter = downloadImage;
//#endregion
export { MarkdownDocx, Packer, markdownDocx as default, getPreset, markdownDocx, presets, resolveStyleConfig, styles };
export { MarkdownDocx, Packer, markdownDocx as default, markdownDocx, getPreset, presets, resolveStyleConfig, styles };
{
"name": "@cylixlee/mdocx",
"version": "0.1.0",
"version": "0.2.0",
"description": "Convert Markdown file to DOCX format",

@@ -42,3 +42,3 @@ "keywords": [

"bin": {
"markdown-docx": "bin/cli.mjs"
"mdocx": "bin/cli.mjs"
},

@@ -54,2 +54,3 @@ "directories": {

"dependencies": {
"@modelcontextprotocol/sdk": "^1.29.0",
"commander": "^13.1.0",

@@ -78,3 +79,3 @@ "docx": "^9.5.1",

"build": "tsdown",
"test": "vitest",
"test": "vitest run",
"test:coverage": "vitest run --coverage",

@@ -81,0 +82,0 @@ "release-it": "release-it",

import * as docx1 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) => 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;
/**
* 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: docx1.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: docx1.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<docx1.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, getPreset, markdownDocx, presets, resolveStyleConfig, styles };