HOS ANY2DOCX: Markdown→DOCX (Mermaid supported) and Mermaid→PNG via Playwright
Project description
HOS_ANY2DOCX
将包含 Mermaid 的 Markdown 转换为 DOCX,并支持将 Mermaid 源文件渲染为 PNG。基于 python-docx 和 playwright。
功能
Markdown → DOCX:支持标题、列表、表格、内部跳转、代码块,Mermaid 图自动渲染并按页面宽度居中缩放。Mermaid → PNG:通过无头 Chromium 渲染 Mermaid SVG 并截图生成 PNG。
安装
python -m pip install HOS_ANY2DOCX
# 首次使用需安装浏览器内核
python -m playwright install chromium
命令行
- 渲染 PNG:
hos-render-mermaid input.mmd output.png # 或 python -m hos_any2docx.render_mermaid input.mmd output.png
- Markdown 转 DOCX:
hos-md2docx input.md output.docx # 或 python -m hos_any2docx.md2docx_mermaid input.md output.docx
使用提示
- Mermaid 块以三引号代码块标注:
```mermaid graph TD A --> B - 若使用内联 Mermaid(不加代码块围栏),包也会自动检测并渲染。
发布流程(PyPI/TestPyPI)
按照 Python Packaging 官方教程进行(Packaging Python Projects)。本项目已配置:
pyproject.toml使用 Setuptools 后端- 入口脚本已注册到
project.scripts README.md与LICENSE已纳入包元数据
本地构建
python -m pip install -U build twine
python -m build
上传到 TestPyPI(推荐先试跑)
- 使用 API Token 文件,例如
c:\Users\LXCXJXHX\Desktop\QUESTION\PYPI.txt,内容以pypi-开头。 - 通过脚本:
./scripts/publish_testpypi.ps1 -TokenPath "c:\Users\LXCXJXHX\Desktop\QUESTION\PYPI.txt"
脚本将使用用户名__token__和文件中的 Token 上传。
上传到 PyPI(正式)
./scripts/publish_pypi.ps1 -TokenPath "c:\Users\LXCXJXHX\Desktop\QUESTION\PYPI.txt"
如果使用账户口令而非 API Token,可将脚本中的用户名参数改为你的用户名(示例:
security_hyacinth),并以口令作为密码。
许可证
MIT License,详见 LICENSE。
致谢
- Python Packaging User Guide: Packaging Python Projects
- Playwright, python-docx, Mermaid
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 hos_m2f-0.3.0.tar.gz.
File metadata
- Download URL: hos_m2f-0.3.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
744ab1aaa99efea26bf9ac526ecb9c7520809ae3e8464916bb866015bd887a8f
|
|
| MD5 |
f07a9b881e48e45813bfc9de267f0c20
|
|
| BLAKE2b-256 |
23cd55d75bf53dc94d627573ae2f629bba69981bbab2b859535948321ddaddec
|
File details
Details for the file hos_m2f-0.3.0-py3-none-any.whl.
File metadata
- Download URL: hos_m2f-0.3.0-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
975024ab2cc7827b8212c00d7833e6aae0941ebe656e89d33296ee4c157ae71c
|
|
| MD5 |
458e4b3438d9ef8e417c8c23a6053df7
|
|
| BLAKE2b-256 |
c470c27b0b5ddd45bb9da635b6ed758ccbcea2f360db602d8f7824e85cd60ee0
|