Skip to main content

Convert convention-based Markdown into standardized DOCX with reusable style presets.

Project description

mdstyledocx

一个按约定编写 Markdown、再一键导出标准化 Word (.docx) 的小工具。

当前设计重点不是“完整支持所有 Markdown 语法”,而是“稳定地把结构化 Markdown 落成统一版式的 Word 文档”。它适合做:

  • 政府公文预设
  • 单位通知 / 简报 / 汇报材料
  • 团队内部统一模板

核心思路

把 Markdown 当成“内容源”,把版式规范抽成“preset”。

你只要按固定约定写 Markdown:

  • #:文档标题
  • ##:一级标题
  • ###:二级标题
  • 空行分段
  • - / * / +:无序列表
  • 1.:有序列表
  • <!-- pagebreak -->:分页

然后执行一次命令,就能得到带统一字体、字号、缩进、页边距的 .docx

内置预设

各 preset 的详细说明都放在 src/mdstyledocx/preset_specs/ 下:

  • default:通用正式文档版式
  • gov-cn:中文政府公文风格基线
  • gov-cn-hei:黑体标题、楷体二级标题、仿宋正文

目录约定:

  • *.json:样式参数、页边距、字体、缩进等机器可读定义
  • *.md:该模板的写作约定、推荐语法和边界说明

使用方式

推荐直接用 uv

uv sync
uv run python -m unittest
uv run mdstyledocx --list-presets
uv run mdstyledocx --show-preset-rules gov-cn
uv run mdstyledocx examples/gov_notice.md -o examples/gov_notice.docx --preset gov-cn

如果不使用 uv,也可以用传统方式:

pip install -e .
python3 -m unittest
mdstyledocx examples/gov_notice.md -o examples/gov_notice.docx --preset gov-cn

自定义预设

可以在内置 preset 基础上再叠加一个 JSON 覆盖文件:

mdstyledocx input.md -o output.docx --preset gov-cn --preset-file my-preset.json

如果想先看某个模板要求什么 Markdown 写法:

mdstyledocx --show-preset-rules gov-cn

示例:

{
  "extends": "gov-cn",
  "styles": {
    "body": {
      "line": 520,
      "line_rule": "exact"
    },
    "title": {
      "size_half_points": 40
    }
  }
}

Markdown 约定

README 只保留通用约定。某个 preset 的专用写法,以对应的 preset_specs/*.md 为准。

通用写法:

# 关于开展示例工作的通知

各有关单位:

为统一输出格式,现将有关事项通知如下。

## 一、工作目标

1. 统一内容源。
2. 统一输出格式。

## 二、工作要求

请各单位按要求执行。

当前边界

当前版本优先保证:

  • 标题、段落、列表、分页可稳定导出
  • 预设版式可复用
  • 产物是标准 .docx

暂未覆盖:

  • 表格
  • 图片
  • 脚注
  • 复杂嵌套列表
  • 目录自动生成

如果后面继续做,这个工具可以自然扩展成:

  • 多个行业 preset 集合
  • frontmatter 驱动的页面元信息
  • 更完整的 Markdown 语法支持
  • GUI 或 Web 包装层

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdstyledocx-0.1.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdstyledocx-0.1.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file mdstyledocx-0.1.0.tar.gz.

File metadata

  • Download URL: mdstyledocx-0.1.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mdstyledocx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5def26598dde8f36ed79e228269532dbaf36f98d3fd2d066c9c46ce6b7effea4
MD5 8f3e2f94773d9653f96db7752dfa440d
BLAKE2b-256 dc1a9f02d4699a670359d0782e19646a97dcba9abaad5dfce024e4dd9e45f6fa

See more details on using hashes here.

File details

Details for the file mdstyledocx-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mdstyledocx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mdstyledocx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b213c7922e8123942dfb20cd64ae8762fa78cff0566d347d05c5938a9312fd52
MD5 22986c23ce14c7962b577c248af33927
BLAKE2b-256 98df512a8578a9f0d8d7b5285f62cfe4a60730273f30dbe4d91607ea7375294e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page