1
0
lanyuanxiaoyao 124ef0e5ce refactor: 重构文档结构,采用渐进式信息披露模式
将 README.md 拆分为多个专题文档,减少认知负荷:
- 用户文档迁移到 docs/ (用户指南、元素、模板、参考等)
- 开发文档迁移到 docs/development/ (架构、模块、规范)
- README.md 精简至 ~290 行,仅保留概览和导航
- 删除 README_DEV.md,内容已迁移
- 归档 OpenSpec 变更 refactor-docs-progressive-disclosure
2026-03-06 15:11:36 +08:00
2026-03-04 10:31:26 +08:00
2026-03-04 10:29:21 +08:00

yaml2pptx

使用 YAML 声明式语法创建 PowerPoint 演示文稿的工具。

功能特性

  • YAML 声明式语法 - 使用简单易读的 YAML 定义演示文稿
  • 智能验证 - 转换前自动检查 YAML 文件,提前发现问题
  • 模板系统 - 支持参数化模板,复用幻灯片布局
  • 丰富的元素类型 - 文本、图片、形状、表格
  • 实时预览 - 浏览器预览模式,支持热重载
  • 灵活尺寸 - 支持 16:9 和 4:3 两种宽高比
  • 模块化架构 - 易于扩展和维护

快速开始

安装

本工具使用 uv 管理依赖。项目依赖在 pyproject.toml 中声明,运行时会自动安装所需的 Python 包。

基本用法

# 转换 YAML 为 PPTX
uv run yaml2pptx.py convert presentation.yaml output.pptx

# 自动生成输出文件名
uv run yaml2pptx.py convert presentation.yaml

# 使用模板库
uv run yaml2pptx.py convert presentation.yaml output.pptx --template ./templates.yaml

实时预览

# 启动预览服务器(自动打开浏览器)
uv run yaml2pptx.py preview presentation.yaml

# 指定端口
uv run yaml2pptx.py preview presentation.yaml --port 8080

预览模式会自动监听文件变化,修改 YAML 文件后浏览器会自动刷新。

验证功能

# 验证 YAML 文件
uv run yaml2pptx.py check presentation.yaml

# 使用模板时验证
uv run yaml2pptx.py check presentation.yaml --template ./templates.yaml

核心概念

YAML 语法基础

metadata:
  size: "16:9"

slides:
  - background:
      color: "#ffffff"
    elements:
      - type: text
        box: [1, 1, 8, 1]
        content: "Hello, World!"
        font:
          size: 44
          bold: true

元素类型

文本元素

- type: text
  box: [x, y, width, height]
  content: "文本内容"
  font:
    size: 18
    bold: true
    color: "#ff0000"

图片元素

- type: image
  box: [x, y, width, height]
  src: "path/to/image.png"

形状元素

- type: shape
  box: [x, y, width, height]
  shape: rectangle
  fill: "#4a90e2"

表格元素

- type: table
  position: [x, y]
  col_widths: [2, 2, 2]
  data:
    - ["表头1", "表头2", "表头3"]
    - ["数据1", "数据2", "数据3"]

模板系统

内联模板

metadata:
  size: "16:9"

templates:
  title-slide:
    vars:
      - name: title
        required: true
    elements:
      - type: text
        box: [1, 2, 8, 1]
        content: "{title}"
        font:
          size: 44
          bold: true

slides:
  - template: title-slide
    vars:
      title: "我的演示文稿"

外部模板库

# 创建 templates.yaml
uv run yaml2pptx.py convert presentation.yaml output.pptx --template ./templates.yaml

字体主题系统

metadata:
  fonts:
    title:
      family: "cjk-sans"
      size: 44
      bold: true
    body:
      family: "sans"
      size: 18

slides:
  - elements:
      - type: text
        content: "标题"
        font: "@title"

常见用例

标题页

metadata:
  size: "16:9"

slides:
  - elements:
      - type: text
        box: [1, 2.5, 8, 1]
        content: "项目名称"
        font:
          size: 44
          bold: true
          align: center

内容页

slides:
  - elements:
      - type: text
        box: [1, 1, 8, 0.8]
        content: "章节标题"
        font:
          size: 32
          bold: true

      - type: text
        box: [1, 2, 8, 3]
        content: "正文内容\n支持多行文本"
        font:
          size: 18

使用模板

metadata:
  size: "16:9"

slides:
  - template: title-slide
    vars:
      title: "第一章"

文档导航

用户文档

开发文档

使用技巧

  1. 开发流程:使用预览模式实时查看效果,确认无误后再生成 PPTX
  2. 模板复用:为常用布局创建模板,保持演示文稿风格一致
  3. 相对路径:图片路径相对于 YAML 文件位置,便于项目管理
  4. 文本换行:文本框默认启用自动换行,无需手动处理长文本

扩展性

yaml2pptx 采用模块化架构,易于扩展:

  • 添加新元素类型:定义新的元素数据类和渲染方法
  • 添加新渲染器:支持输出到其他格式(如 PDF
  • 自定义模板:创建符合你需求的模板库

详见 开发文档

依赖项

  • python-pptx - PowerPoint 文件生成
  • pyyaml - YAML 解析
  • flask - 预览服务器
  • watchdog - 文件监听

依赖在 pyproject.toml 中声明,由 uv 自动管理,无需手动安装。

测试

# 运行所有测试
uv run pytest

# 运行特定类型的测试
uv run pytest tests/unit/       # 单元测试
uv run pytest tests/integration/  # 集成测试
uv run pytest tests/e2e/        # 端到端测试

贡献

欢迎贡献代码、报告问题或提出建议!

开发者请参阅 开发文档 了解代码结构和开发规范。

许可证

MIT License

Description
No description provided
Readme 1.1 MiB
Languages
Python 100%