A Python package to convert Markdown to Docx with custom font and embedded images.
Project description
md2docx
md2docx 是一个 Python 工具,用于将 Markdown 文件转换为美观的 Docx 文档。它支持自定义字体、数学公式、表格、图片嵌入等功能,特别针对中文字体支持进行了优化。
功能特性
- 多风格模版支持:内置多种专业风格模版(专业、学术、创意),支持使用现有
.docx作为模版继承样式。 - 中文字体优化:默认使用 "Microsoft YaHei" (微软雅黑) 或 "SimSun" (宋体),解决生成文档中中文字体显示问题。
- 数学公式支持:支持 LaTeX 格式的行内公式 ($...$) 和块级公式 ($$...$$),完美转换为 Word 原生公式。
- 图片嵌入:支持本地图片和网络图片(自动下载并嵌入)。
- 表格支持:支持标准 Markdown 表格语法。
- Agent 友好:提供
convert_to_bytes接口,支持在内存中生成文档流,适配 AI Agent 和 Web API。 - Agent Skill:提供符合标准规范的 Skill 封装,方便 OpenClaw 等 AI 框架直接调用。
安装
通过 PyPI 安装 (推荐)
pip install md2docx-pro
从源码安装
git clone https://github.com/yourusername/md2docx.git
cd md2docx
pip install .
使用方法
命令行工具 (CLI)
md2docx <输入文件.md> <输出文件.docx> [选项]
示例:
-
基本转换:
md2docx input.md output.docx
-
使用内置专业模版:
md2docx input.md output.docx --template professional_template.docx
-
指定字体:
md2docx input.md output.docx --font "SimSun"
Python SDK
from md2docx import MarkdownToDocx
md_content = "# Hello World"
converter = MarkdownToDocx(template_path="professional_template.docx")
# 1. 转换为本地文件
converter.convert(md_content, "output.docx")
# 2. 转换为内存流 (适用于 AI Agent)
docx_bytes = converter.convert_to_bytes(md_content)
内置模版
professional_template.docx: 商务专业风格,现代无衬线字体 (Arial + 微软雅黑)。academic_template.docx: 严谨学术风格,衬线字体 (Times New Roman + 宋体),1.5 倍行距。creative_template.docx: 活泼创意风格,橙色/蓝色主题,适合演示文档。
AI Agent 集成
本项目包含一个 md2docx-skill 目录,符合 OpenClaw 等 AI 框架的 Skill 规范。AI Agent 可以通过该 Skill 快速了解如何调用 md2docx 生成文档。
许可证
本项目采用 MIT 许可证。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file md2docx_pro-0.1.4.tar.gz.
File metadata
- Download URL: md2docx_pro-0.1.4.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
578d6b727ae35ff389d5472d335e4d6149d9a9558114baf13ca83b574a003b77
|
|
| MD5 |
69e0abb9e597cca02572cfec80f4ebfd
|
|
| BLAKE2b-256 |
986d3815adfc69d24c4d1455b071454500bee1d195f3e47c2237db7caef42205
|
Provenance
The following attestation bundles were made for md2docx_pro-0.1.4.tar.gz:
Publisher:
publish.yml on wgwang/md2docx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2docx_pro-0.1.4.tar.gz -
Subject digest:
578d6b727ae35ff389d5472d335e4d6149d9a9558114baf13ca83b574a003b77 - Sigstore transparency entry: 1260820733
- Sigstore integration time:
-
Permalink:
wgwang/md2docx@aebca67a32a9b6ad3d6859304475c31cc495ad7b -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/wgwang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@aebca67a32a9b6ad3d6859304475c31cc495ad7b -
Trigger Event:
push
-
Statement type:
File details
Details for the file md2docx_pro-0.1.4-py3-none-any.whl.
File metadata
- Download URL: md2docx_pro-0.1.4-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfafb705dc95bdb46002aec9e1c6e16cb756436c6638cd8b86f998dbccd7d010
|
|
| MD5 |
dc28d99c794b1da226f1f8db341317fe
|
|
| BLAKE2b-256 |
c1c2c7d565529e1f45c9dad784776e4ab35d25967ba9ed51b3299803078919aa
|
Provenance
The following attestation bundles were made for md2docx_pro-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on wgwang/md2docx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2docx_pro-0.1.4-py3-none-any.whl -
Subject digest:
dfafb705dc95bdb46002aec9e1c6e16cb756436c6638cd8b86f998dbccd7d010 - Sigstore transparency entry: 1260820835
- Sigstore integration time:
-
Permalink:
wgwang/md2docx@aebca67a32a9b6ad3d6859304475c31cc495ad7b -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/wgwang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@aebca67a32a9b6ad3d6859304475c31cc495ad7b -
Trigger Event:
push
-
Statement type: