feat: add YAML validation with check command and auto-validation
Implements comprehensive validation before PPTX conversion to catch errors early. Includes element-level validation (colors, fonts, table consistency) and system-level validation (geometry, resources). Supports standalone check command and automatic validation during conversion.
This commit is contained in:
70
README.md
70
README.md
@@ -5,6 +5,7 @@
|
||||
## ✨ 功能特性
|
||||
|
||||
- 📝 **YAML 声明式语法** - 使用简单易读的 YAML 定义演示文稿
|
||||
- ✅ **智能验证** - 转换前自动检查 YAML 文件,提前发现问题
|
||||
- 🎨 **模板系统** - 支持参数化模板,复用幻灯片布局
|
||||
- 🧩 **丰富的元素类型** - 文本、图片、形状、表格
|
||||
- 👁️ **实时预览** - 浏览器预览模式,支持热重载
|
||||
@@ -20,28 +21,83 @@
|
||||
### 基本用法
|
||||
|
||||
```bash
|
||||
# 生成 PPTX 文件(自动命名为 input.pptx)
|
||||
uv run yaml2pptx.py presentation.yaml
|
||||
# 使用 convert 子命令(推荐)
|
||||
uv run yaml2pptx.py convert presentation.yaml output.pptx
|
||||
|
||||
# 指定输出文件名
|
||||
uv run yaml2pptx.py presentation.yaml output.pptx
|
||||
# 自动生成输出文件名
|
||||
uv run yaml2pptx.py convert presentation.yaml
|
||||
|
||||
# 使用模板
|
||||
uv run yaml2pptx.py presentation.yaml output.pptx --template-dir ./templates
|
||||
uv run yaml2pptx.py convert presentation.yaml output.pptx --template-dir ./templates
|
||||
|
||||
# 传统用法(向后兼容)
|
||||
uv run yaml2pptx.py presentation.yaml output.pptx
|
||||
```
|
||||
|
||||
### 实时预览
|
||||
|
||||
```bash
|
||||
# 启动预览服务器(自动打开浏览器)
|
||||
uv run yaml2pptx.py presentation.yaml --preview
|
||||
uv run yaml2pptx.py convert presentation.yaml --preview
|
||||
|
||||
# 指定端口
|
||||
uv run yaml2pptx.py presentation.yaml --preview --port 8080
|
||||
uv run yaml2pptx.py convert presentation.yaml --preview --port 8080
|
||||
|
||||
# 传统用法(向后兼容)
|
||||
uv run yaml2pptx.py presentation.yaml --preview
|
||||
```
|
||||
|
||||
预览模式会自动监听文件变化,修改 YAML 文件后浏览器会自动刷新。
|
||||
|
||||
### 验证功能
|
||||
|
||||
在转换前验证 YAML 文件,提前发现问题:
|
||||
|
||||
```bash
|
||||
# 独立验证命令
|
||||
uv run yaml2pptx.py check presentation.yaml
|
||||
|
||||
# 使用模板时验证
|
||||
uv run yaml2pptx.py check presentation.yaml --template-dir ./templates
|
||||
```
|
||||
|
||||
验证功能会检查:
|
||||
- ✅ YAML 语法和结构
|
||||
- ✅ 元素是否超出页面范围
|
||||
- ✅ 图片和模板文件是否存在
|
||||
- ✅ 颜色格式是否正确
|
||||
- ✅ 字体大小是否合理
|
||||
- ✅ 表格数据是否一致
|
||||
|
||||
**自动验证**:转换时默认会自动验证,如果发现错误会终止转换。可以使用 `--no-check` 跳过验证:
|
||||
|
||||
```bash
|
||||
# 跳过自动验证(convert 子命令)
|
||||
uv run yaml2pptx.py convert presentation.yaml --no-check
|
||||
|
||||
# 跳过自动验证(传统用法)
|
||||
uv run yaml2pptx.py presentation.yaml --no-check
|
||||
```
|
||||
|
||||
**验证结果示例**:
|
||||
|
||||
```
|
||||
🔍 正在检查 YAML 文件...
|
||||
|
||||
❌ 错误 (2):
|
||||
[幻灯片 2, 元素 1] 无效的颜色格式: red (应为 #RRGGBB)
|
||||
[幻灯片 3, 元素 2] 图片文件不存在: logo.png
|
||||
|
||||
⚠️ 警告 (1):
|
||||
[幻灯片 1, 元素 1] 元素右边界超出: 10.50 > 10
|
||||
|
||||
检查完成: 发现 2 个错误, 1 个警告
|
||||
```
|
||||
|
||||
- **ERROR**:阻止转换的严重问题(文件不存在、语法错误等)
|
||||
- **WARNING**:影响视觉效果的问题(元素超出页面、字体太小等)
|
||||
- **INFO**:优化建议
|
||||
|
||||
## 📖 YAML 语法
|
||||
|
||||
### 最小示例
|
||||
|
||||
Reference in New Issue
Block a user