oyf518

md-to-word

0
0
# Install this skill:
npx skills add oyf518/md_to_word_skill

Or install specific skill: npx add-skill https://github.com/oyf518/md_to_word_skill

# Description

This skill converts Markdown files to Word documents with proper Chinese formatting. Use it when the user asks to "convert markdown to word", "generate word from md", "export markdown as docx", "MD转Word", "markdown转word文档", or discusses document format conversion.

# SKILL.md


name: md-to-word
description: This skill converts Markdown files to Word documents with proper Chinese formatting. Use it when the user asks to "convert markdown to word", "generate word from md", "export markdown as docx", "MD转Word", "markdown转word文档", or discusses document format conversion.
version: 1.0.0


Markdown to Word Converter

将 Markdown 文件转换为格式化的 Word 文档,专为中文文档优化。

使用场景

当需要将 Markdown 格式的文档(特别是技术方案、投标文档等)转换为 Word 格式时使用。

实施步骤

  1. 确保安装了依赖:
    bash pip install -r requirements.txt

  2. 运行转换脚本:
    bash python scripts/md_to_word.py <markdown文件路径> [-o 输出文件路径]

转换格式特性

页面设置

  • A4 纸张
  • 页边距:上下左右各 2.5cm

字体样式

  • 一级标题:黑体,二号(22磅)
  • 二级标题:黑体,三号(16磅)
  • 三级标题:黑体,小三号(15磅)
  • 四级标题:宋体,小四号(12磅)
  • 五级标题:宋体,小四号(12磅)
  • 正文:宋体,小四号(12磅),首行缩进2字符

行距设置

  • 标题行距:1.2倍
  • 正文行距:1.5倍

支持的 Markdown 语法

  • 标题(H1-H5)
  • 粗体、斜体、删除线
  • 链接
  • 有序列表、无序列表
  • 表格(带表头样式)

参数说明

  • input: (必需) 输入的 Markdown 文件路径
  • -o, --output: (可选) 输出的 Word 文件路径,默认与输入文件同名

示例

基本用法

python scripts/md_to_word.py 技术方案.md

生成 技术方案.docx

指定输出文件

python scripts/md_to_word.py 技术方案.md -o 输出文件.docx

表格样式

  • 表头行:黑体小四号,居中对齐,灰色背景(#D9D9D9)
  • 数据行:宋体五号(10.5磅)
  • 自动应用表格样式:Light Grid Accent 1

注意事项

  • 确保输入的 Markdown 文件使用 UTF-8 编码
  • 表格必须使用标准的 Markdown 表格语法(| 分隔)
  • 连续空行会被自动合并为单个空行
  • 转换后会保留文档的基本结构,但某些复杂格式可能需要手动调整

适用场景

  • 投标文档格式化
  • 技术方案文档转换
  • 中文公文格式输出
  • Markdown 文档的 Word 格式归档

# README.md

Markdown to Word Converter Skill

这是一个 Claude Code 技能(Skill),用于将 Markdown 文件转换为格式化的 Word 文档,专为中文文档优化。

功能特性

完整的 Markdown 语法支持

  • 标题:支持 H1-H5 五级标题
  • 文本格式:粗体、斜体、删除线
  • 列表:有序列表和无序列表
  • 表格:自动识别并格式化表格
  • 代码块:使用等宽字体,浅灰色背景
  • 链接:保留超链接格式

中文公文格式标准

  • 页面设置:A4 纸张,四周页边距 2.5cm
  • 标题字体
  • 一级标题:黑体,二号(22磅)
  • 二级标题:黑体,三号(16磅)
  • 三级标题:黑体,小三号(15磅)
  • 四级标题:宋体,小四号(12磅)
  • 五级标题:宋体,小四号(12磅)
  • 正文格式:宋体,小四号(12磅),首行缩进 2 字符
  • 行距设置:标题 1.2 倍,正文 1.5 倍
  • 表格样式
  • 表头:黑体小四号,居中对齐,灰色背景(#D9D9D9)
  • 数据行:宋体五号(10.5磅)
  • 自动应用边框样式
  • 代码块格式
  • 字体:Consolas 等宽字体
  • 字号:小五号(9磅)
  • 背景:浅灰色(#F5F5F5)
  • 行距:1.0 倍
  • 左右缩进:各 0.5cm

安装

1. 安装依赖

pip install -r requirements.txt

2. 安装为 Claude Code Skill

将整个目录复制到 Claude Code 的 skills 目录:

cp -r md_to_word_skill ~/.claude/skills/md-to-word

或者直接在当前目录使用。

使用方法

作为 Claude Code Skill 使用

在 Claude Code 中,当需要转换 Markdown 文件时,使用以下触发词:

  • "convert markdown to word"
  • "generate word from md"
  • "export markdown as docx"
  • "MD转Word"
  • "markdown转word文档"

Claude Code 会自动调用此技能进行转换。

作为独立脚本使用

# 基本用法
python scripts/md_to_word.py <markdown文件路径>

# 指定输出文件
python scripts/md_to_word.py <markdown文件路径> -o <输出文件路径>

示例

# 转换单个文件
python scripts/md_to_word.py 技术方案.md

# 指定输出文件名
python scripts/md_to_word.py 技术方案.md -o 输出文件.docx

使用场景

  • 投标文档格式化
  • 技术方案文档转换
  • 中文公文格式输出
  • Markdown 文档的 Word 格式归档
  • 清单、报价单等业务文档转换

转换示例

Markdown 输入

# 项目技术方案

## 系统架构

本系统采用**四层架构**设计:

- 感知层:数据采集
- 传输层:数据传输
- 平台层:数据处理
- 应用层:业务应用

### 核心功能

| 功能模块 | 说明 | 优先级 |
|---------|------|--------|
| 用户管理 | RBAC权限控制 | 高 |
| 数据采集 | 实时数据采集 | 高 |

Word 输出

  • A4 纸张,标准页边距
  • "项目技术方案":黑体二号
  • "系统架构":黑体三号
  • "感知层"等列表项:宋体小四号,保持粗体格式
  • 表格:带灰色表头和边框

技术实现

  • Python 3.6+
  • python-docx:Word 文档生成
  • 正则表达式:Markdown 语法解析

文件结构

md_to_word_skill/
├── SKILL.md           # Claude Code 技能定义
├── README.md          # 本文件
├── requirements.txt   # Python 依赖
└── scripts/
    └── md_to_word.py  # 主转换脚本

更新日志

v1.0.0 (2025-01-05)

  • 初始版本
  • 支持完整的 Markdown 语法
  • 中文公文格式标准
  • 表格格式化
  • 代码块支持
  • 列表内联格式解析(粗体、斜体等)
  • 修复背景色 XML 格式问题

许可证

MIT License

贡献

欢迎提交 Issue 和 Pull Request!

作者

Created for Claude Code users who need to convert Chinese Markdown documents to Word format.

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.