← 返回
未分类

Markdown to Word (.docx) Converter

Convert Markdown files to formatted Word (.docx) documents with automatic template style detection. Use this skill whenever the user mentions converting Mark...
将 Markdown 文件转换为格式化的 Word (.docx) 文档,自动识别模板样式。当用户提到将 Markdown 转换为 Word 时使用此技能。
krabww krabww 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 1
Stars
📥 540
下载
💾 26
安装
1
版本
#chinese#document#docx#latest#markdown#mermaid#typesetting#word

概述

Markdown to Word (.docx) Converter

Convert Markdown files to professionally formatted Word documents, with automatic template style extraction and Mermaid diagram rendering.

How It Works

The bundled script (scripts/md_to_docx.py) handles the entire conversion:

  1. Parse Markdown into structured blocks (headings, body, lists, tables, code, quotes)
  2. Extract styles from an optional Word template (.doc or .docx) — font, size, alignment, spacing
  3. Apply formatting to each block, preserving inline Markdown (bold, italic, code, strikethrough)
  4. Render Mermaid diagrams to PNG via mmdc (mermaid-cli) and embed them as images
  5. Output a ready-to-use .docx file

Dependencies

The script requires:

  • python-docx: pip install python-docx
  • mmdc (for Mermaid rendering): npm install -g @mermaid-js/mermaid-cli
  • Chrome or Chromium: must be installed locally (auto-detected on macOS/Windows/Linux)

On macOS, .doc templates are converted via the built-in textutil. On Linux, LibreOffice is used as fallback.

Usage

Basic conversion (default Chinese typesetting)

python3 scripts/md_to_docx.py input.md -o output.docx

With template (auto-extract formatting)

python3 scripts/md_to_docx.py input.md -o output.docx -t template.doc

When Invoked as a Skill

When the user asks to convert a Markdown file to Word:

  1. Identify the input file — the user will typically specify a .md file path
  2. Check for a template — ask if they have a .doc/.docx template, or check if one exists in common locations (docs/, templates/)
  3. Ensure dependencies are installed:

```bash

pip3 install python-docx

npm list -g @mermaid-js/mermaid-cli 2>/dev/null || npm install -g @mermaid-js/mermaid-cli

```

  1. Run the script from the skill's scripts/ directory:

```bash

python3 /scripts/md_to_docx.py -o [-t ]

```

  1. Report results — tell the user the output path and whether all Mermaid diagrams rendered successfully

Template Format Detection

When a template is provided, the script analyzes it automatically:

  • Title levels are identified by font size and alignment (largest centered = chapter title, etc.)
  • Body text is identified by paragraphs with first-line indentation
  • Page setup (margins, paper size) is copied from the template
  • Chinese font pairing is preserved (e.g., Times New Roman ↔ 宋体, Arial ↔ 黑体)

If no template is provided, these defaults are used (Chinese publishing standard):

ElementFontSizeAlignment
--------------------------------
Chapter title (h1)黑体18ptCenter
Section title (h2)黑体16ptCenter
Subsection (h3)黑体14ptLeft
Body text宋体10.5pt (五号)Justify, 2-char indent
CodeConsolas9ptLeft
Quote楷体10.5ptLeft indent, italic

Supported Markdown Features

  • Headings: h1–h6 (h1 = chapter, h2 = section, h3 = subsection, h4+ = sub-subsection)
  • Body text with inline: bold, italic, code, ~~strikethrough~~, bold italic
  • Bullet lists (- or *) and ordered lists (1.)
  • Tables with header detection
  • Code blocks with language label
  • Mermaid diagrams rendered to embedded PNG images
  • Block quotes and horizontal rules

Mermaid Diagram Handling

Mermaid code blocks are rendered to PNG via mmdc using the local Chrome browser. If rendering fails (e.g., Chrome not found, syntax error), the diagram falls back to a code block display.

Common Mermaid compatibility fixes are applied automatically:

  • subgraph names containing colons are quoted
  • Parentheses in subgraph names are escaped

Cross-Platform Notes

  • macOS: Chrome auto-detected at /Applications/Google Chrome.app/...
  • Windows: Checks Program Files and LocalAppData
  • Linux: Checks /usr/bin/google-chrome, /usr/bin/chromium, /snap/bin/chromium
  • .doc conversion: Uses textutil on macOS, libreoffice on Linux

Limitations

  • No support for footnotes, images, or links (Markdown image URLs are not fetched)
  • Math equations (LaTeX) are preserved as plain text
  • Nested lists deeper than one level are flattened
  • Template detection works best with templates that have clear formatting differentiation between headings and body text

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-31 07:05 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

office-efficiency

Word / DOCX

ivangdavila
创建、检查和编辑 Microsoft Word 文档及 DOCX 文件,支持样式、编号、修订记录、表格、分节符及兼容性检查等功能。
★ 476 📥 157,726
office-efficiency

Excel / XLSX

ivangdavila
创建、检查和编辑 Microsoft Excel 工作簿及 XLSX 文件,支持可靠的公式、日期、类型、格式、重算及模板保留功能。
★ 400 📥 149,909
office-efficiency

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 937 📥 187,756