md-to-docx

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Markdown to Word (.docx) Skill

Markdown转Word(.docx)Skill

Convert Markdown (
.md
) files into professionally formatted Word (
.docx
) documents with embedded PNG images. Uses pure JavaScript via the
docx
and
marked
npm packages — no Pandoc, LibreOffice, or any native binary required.
将Markdown(
.md
)文件转换为带有嵌入式PNG图片的专业格式Word(
.docx
)文档。通过
docx
marked
npm包采用纯JavaScript实现——无需Pandoc、LibreOffice或任何原生二进制文件。

How to Convert

转换方法

bash
undefined
bash
undefined

Install dependencies (one-time, from the scripts folder)

安装依赖(仅需一次,在scripts目录下执行)

cd skills/md-to-docx/scripts && npm install
cd skills/md-to-docx/scripts && npm install

Convert (run from workspace root)

转换(在工作区根目录执行)

node skills/md-to-docx/scripts/md-to-docx.mjs <input.md> [output.docx]

If `output.docx` is omitted, it defaults to `<input-basename>.docx` in the current directory.
node skills/md-to-docx/scripts/md-to-docx.mjs <input.md> [output.docx]

如果省略`output.docx`,默认会在当前目录生成`<input-basename>.docx`文件。

Skill Folder Contents

Skill目录内容

FilePurpose
SKILL.md
This instruction file
scripts/md-to-docx.mjs
Node.js Markdown-to-Word converter
scripts/package.json
Dependencies (
docx
,
marked
)
文件用途
SKILL.md
本说明文档
scripts/md-to-docx.mjs
Node.js Markdown转Word转换器
scripts/package.json
依赖包(
docx
marked

Prerequisites

前置要求

RequirementVersionNotes
Node.js18+Required runtime
docx
9+Pure JS Word document generator
marked
15+Markdown parser
No native binaries. No system-level installs. Works on Windows, macOS, and Linux.
要求版本说明
Node.js18+必需的运行时环境
docx
9+纯JS Word文档生成器
marked
15+Markdown解析器
无需原生二进制文件,无需系统级安装,可在Windows、macOS和Linux系统上运行。

Features

功能特性

The converter:
  • Extracts YAML front-matter — uses
    title
    ,
    date
    ,
    version
    ,
    audience
    for the title page
  • Generates a title page — with project name, subtitle, date, version, and audience
  • Generates a table of contents — built from H1-H3 headings
  • Embeds PNG images — resolves
    ![alt](path)
    references relative to the input
    .md
    file, reads the PNG, and embeds it inline in the Word document
  • Styled output — Calibri font, colored headings (
    #1F3864
    ), styled tables with alternating row colors, code blocks in Consolas
  • Handles all Markdown elements — headings, paragraphs, tables, code blocks, lists, images, links, horizontal rules
该转换器具备以下功能:
  • 提取YAML前置元数据——使用
    title
    date
    version
    audience
    生成标题页
  • 生成标题页——包含项目名称、副标题、日期、版本和受众信息
  • 生成目录——基于H1-H3标题构建
  • 嵌入PNG图片——解析Markdown中
    ![alt](path)
    引用,路径相对于输入的
    .md
    文件,读取PNG并将其嵌入Word文档中
  • 样式化输出——采用Calibri字体、彩色标题(
    #1F3864
    )、带有交替行颜色的样式化表格、Consolas字体的代码块
  • 支持所有Markdown元素——标题、段落、表格、代码块、列表、图片、链接、水平线

Image Embedding

图片嵌入

The converter automatically embeds PNG images referenced in the Markdown:
markdown
![High-Level Architecture](diagrams/high-level-architecture.drawio.png)
The image path is resolved relative to the input Markdown file. The PNG is read, dimensions are extracted from the PNG header, and the image is scaled to fit within 6 inches width while preserving aspect ratio.
If an image file is not found, a placeholder
[Image not found: <path>]
is inserted.
转换器会自动嵌入Markdown中引用的PNG图片:
markdown
![High-Level Architecture](diagrams/high-level-architecture.drawio.png)
图片路径是相对于输入Markdown文件进行解析的。读取PNG后,从PNG头中提取尺寸,并将图片缩放至宽度不超过6英寸,同时保持宽高比。
如果未找到图片文件,将插入占位符
[Image not found: <path>]

Front-Matter Format

前置元数据格式

yaml
---
title: Project Name — Project Summary
date: 2025-01-15
version: 1.0
audience: Engineering Team, Architects, Stakeholders
---
The title is split on
or
into main title and subtitle for the title page.
yaml
---
title: Project Name — Project Summary
date: 2025-01-15
version: 1.0
audience: Engineering Team, Architects, Stakeholders
---
标题会按
分割为主标题和副标题,用于标题页显示。