Skip to content
Back to skills

Md2word

ASecurity

Markdown转Word文档技能。将Markdown文档转换为符合中文排版标准的专业格式Word文档,支持多种预设格式。适用于正式文档、论文、报告等需要规范排版的文档转换。

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 25, 2026
toolspythongobashgit

Works with

  • cli

Security analysis

A92/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 20 files and shows the line behind each finding

Scanned September 25, 2026

npx -y skills add CSlawyer1985/legal-skillhub --skill md2word --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Md2word?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Md2word
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/cslawyer1985-md2word/badge)](https://www.skillsdirectory.com/skills/cslawyer1985-md2word)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: md2word
description: Markdown转Word文档技能。将Markdown文档转换为符合中文排版标准的专业格式Word文档,支持多种预设格式。适用于正式文档、论文、报告等需要规范排版的文档转换。
license: MIT
metadata:
  homepage: https://github.com/cat-xierluo/legal-skills
  author: 杨卫薪律师(微信ywxlaw)
  version: 1.1.8
---

# Markdown转Word文档Skill

## 概述

将 Markdown 文档转换为符合中文排版标准的 Word 文档。支持完整的 Markdown 语法,自动应用专业格式设置。

## 依赖要求

### Python 依赖

```bash
pip install python-docx Pillow beautifulsoup4 PyYAML
```

### 可选依赖

```bash
npm install -g @mermaid-js/mermaid-cli   # Mermaid 图表渲染
brew install librsvg                       # SVG→PNG(推荐,rsvg-convert)
# 或 pip install cairosvg                  # SVG→PNG 备选
# 或 npm install puppeteer                 # SVG→PNG 备选(scripts/svg2png.js)
```

> 正文内联 `<svg>...</svg>` 块会自动渲染为 PNG 嵌入,渲染优先级 rsvg-convert → cairosvg → svg2png.js(puppeteer),三者任一即可;全部不可用时降级为代码框显示 SVG 源码。

## 快速开始

主转换脚本:`scripts/md2word.py`

```bash
# 基本转换
python scripts/md2word.py input.md output.docx

# 使用预设格式
python scripts/md2word.py input.md --preset=academic

# 使用自定义配置
python scripts/md2word.py input.md --config=my-config.yaml

# 脚注/尾注模式(默认 footnote 页面脚注;endnote=文档末注释+上标编号)
python scripts/md2word.py input.md --notes=endnote

# 全书合并:多章 md → 单 docx(目录+章间分页+页眉,配合 -o 指定输出)
python scripts/md2word.py --book ch01.md ch02.md ch03.md -o book.docx --preset=book-publish
```

## 配置系统

### 内置预设

预设信息从 YAML 文件动态读取,运行以下命令查看完整列表:

```bash
python scripts/config.py --list
```

常用预设:

- **legal** — 法律文书格式(默认)
- **service-plan** — 法律服务方案(含分层配色)
- **minimal** — 极简格式
- **academic** — 学术论文格式
- **report** — 工作报告格式
- **book-publish** — 中文书籍出版格式(正文宋体、标题黑体、TOC/页眉书名,配合 `--book` 全书合并导出)

> 完整配置见 `assets/presets/*.yaml`,设计说明见 `assets/theme-notes/`

### 自定义配置

复制配置模板并修改:
```bash
cp assets/config-template.yaml my-config.yaml
```

### Word 模板文件

将 `.docx` 模板放入 `assets/templates/` 目录,或使用 `--template` 指定。

**Word 模板 vs 配置文件**:
- **Word 模板**:控制视觉元素(页眉、页脚、Logo)
- **配置文件**:控制格式参数(字号、行距、页边距)

## 参考文档

- **配置参考**: [references/config-reference.md](references/config-reference.md)
- **样式映射**: [references/style-mappings.md](references/style-mappings.md)
- **使用示例**: [references/examples.md](references/examples.md)

## 错误处理

- **文件编码**:自动检测 UTF-8 和 GBK
- **模板找不到**:使用默认格式创建新文档
- **Mermaid 失败**:降级为文本描述
- **图片过大**:自动压缩和调整尺寸

## 目录结构

```
md2word/
├── SKILL.md               # 本文档
├── CHANGELOG.md           # 版本记录
├── references/            # 参考文档
│   ├── config-reference.md
│   ├── style-mappings.md
│   └── examples.md
├── scripts/               # 转换脚本
│   ├── md2word.py         # 主脚本
│   ├── config.py          # 配置模块(含 --list 查看预设)
│   ├── extract_template_config.py  # 从 Word 模板提取配置
│   ├── formatter.py       # 文本格式化模块
│   ├── table_handler.py   # 表格处理模块
│   └── chart_handler.py   # 图表渲染模块
└── assets/                # 资源文件
    ├── presets/           # YAML 预设配置
    ├── theme-notes/       # 预设设计说明文档
    ├── templates/         # Word 模板文件
    └── config-template.yaml
```

Files in this skill

  • CHANGELOG.md21 KB
  • DECISIONS.md16.1 KB
  • README.md3.9 KB
  • SKILL.md4.2 KB
  • _meta.json126 B
  • assets/config-template.yaml6 KB
  • assets/presets/academic.yaml2.5 KB
  • assets/presets/book-publish.yaml4.4 KB
  • assets/presets/legal.yaml4.1 KB
  • assets/presets/minimal.yaml2.4 KB
  • assets/presets/report.yaml2.6 KB
  • assets/presets/service-plan.yaml3.4 KB
  • assets/theme-notes/academic.md1.7 KB
  • assets/theme-notes/law-firm.md2 KB
  • assets/theme-notes/minimal.md906 B
  • assets/theme-notes/report.md1.9 KB
  • assets/theme-notes/service-plan.md2.1 KB
  • assets/theme-notes/tech-doc.md1.4 KB
  • references/config-reference.md5.3 KB
  • references/examples.md5.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…