1
0
Files
lanyuanxiaoyao cd7988cbd5 feat: initial implementation of html2pptx with OpenSpec documentation
Add core Python script (yaml2pptx.py) for converting YAML to PowerPoint:
- Element rendering: text, image, shape, table, chart
- Template system with placeholders
- PPTX generation with python-pptx

OpenSpec workflow setup:
- 3 archived changes: browser-preview, template-dir-cli, yaml-to-pptx
- 7 main specifications covering all core modules
- Config and documentation structure

30 files changed, 4984 insertions(+)
2026-03-02 14:28:25 +08:00

45 lines
2.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## Why
当前脚本默认使用相对路径 `templates_dir='templates'` 加载模板,这限制了脚本的可移植性——脚本只能在包含 templates 目录的项目根目录下运行。为了让脚本可以在任何位置使用,需要支持通过命令行参数明确指定模板目录,并移除隐式的默认行为。
## What Changes
- 添加 `--template-dir` 命令行参数,允许用户指定模板文件目录
- **BREAKING**: 移除默认模板目录行为,使用模板时必须通过 `--template-dir` 明确指定模板目录
- 添加模板名称验证,禁止在模板名称中使用路径分隔符(`/``\`),确保模板只能从指定目录的一层加载
- 改进错误提示信息,明确告知用户模板查找位置和失败原因
- 不使用模板的纯自定义幻灯片不受影响,无需指定 `--template-dir`
## Capabilities
### New Capabilities
- `template-directory-cli`: 支持通过命令行参数指定模板目录,包括参数解析、路径验证、错误提示
### Modified Capabilities
- `template-system`: 修改模板加载逻辑,从硬编码的 `templates/` 目录改为必须明确指定的目录;添加模板名称验证规则
## Impact
**代码影响**:
- `Template.__init__` 方法184行修改模板路径解析逻辑添加名称验证
- `Presentation.__init__` 方法610行移除默认 templates_dir 参数
- `parse_args` 函数756行添加 `--template-dir` 参数定义
- `main` 函数775行传递 template_dir 参数给 Presentation
**用户影响**:
- **破坏性变更**: 现有使用模板的用户必须在命令行添加 `--template-dir` 参数
- 不使用模板的用户不受影响
- 脚本可以在任何位置运行,不再依赖特定的目录结构
**示例**:
```bash
# 之前(只能在项目根目录运行)
uv run yaml2pptx.py presentation.yaml
# 之后(可以在任何位置运行,但使用模板时必须指定目录)
uv run yaml2pptx.py presentation.yaml --template-dir ./templates
uv run yaml2pptx.py presentation.yaml --template-dir /path/to/templates
```