1
0
Files
PPTX/openspec/changes/archive/2026-03-02-add-yaml-validation/tasks.md
lanyuanxiaoyao 83ff827ad1 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.
2026-03-02 18:14:45 +08:00

76 lines
3.1 KiB
Markdown
Raw 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.
## 1. 验证结果数据结构
- [x] 1.1 创建 validators/ 目录结构
- [x] 1.2 实现 validators/result.py 中的 ValidationIssue 数据类
- [x] 1.3 实现 validators/result.py 中的 ValidationResult 数据类
- [x] 1.4 实现 ValidationResult.has_errors() 方法
- [x] 1.5 实现 ValidationResult.format_output() 方法,支持图标和分组显示
## 2. 元素类验证增强
- [x] 2.1 在 core/elements.py 中添加颜色格式验证工具函数 _is_valid_color()
- [x] 2.2 为 TextElement 类添加 validate() 方法,检查颜色格式和字体大小
- [x] 2.3 为 ImageElement 类添加 validate() 方法,检查必需字段
- [x] 2.4 为 ShapeElement 类添加 validate() 方法,检查颜色格式和形状类型枚举
- [x] 2.5 为 TableElement 类添加 validate() 方法,检查数据完整性
## 3. 几何验证器
- [x] 3.1 创建 validators/geometry.py 文件
- [x] 3.2 实现 GeometryValidator 类
- [x] 3.3 实现元素边界检查方法,支持 0.1 英寸容忍度
- [x] 3.4 实现表格边界检查方法
- [x] 3.5 实现元素完全在页面外的检查
## 4. 资源验证器
- [x] 4.1 创建 validators/resource.py 文件
- [x] 4.2 实现 ResourceValidator 类
- [x] 4.3 实现图片文件存在性检查,支持相对路径和绝对路径
- [x] 4.4 实现模板文件存在性检查
- [x] 4.5 实现模板文件结构验证(检查 elements 字段)
## 5. 主验证器
- [x] 5.1 创建 validators/validator.py 文件
- [x] 5.2 实现 Validator 类的 validate() 方法
- [x] 5.3 集成 YAML 加载(复用 loaders/yaml_loader.py
- [x] 5.4 集成元素级验证(调用元素类的 validate() 方法)
- [x] 5.5 集成几何验证器
- [x] 5.6 集成资源验证器
- [x] 5.7 在 validators/__init__.py 中导出主验证器
## 6. 命令行接口 - check 子命令
- [x] 6.1 修改 yaml2pptx.py使用 argparse 的 subparsers 添加 check 子命令
- [x] 6.2 实现 check 子命令的参数解析input, --template-dir
- [x] 6.3 实现 check 子命令的处理函数,调用验证器
- [x] 6.4 实现验证结果的命令行输出
- [x] 6.5 根据验证结果返回正确的退出码(有 ERROR 返回非零)
## 7. 命令行接口 - 自动验证
- [x] 7.1 在转换命令中添加 --no-check 选项
- [x] 7.2 在转换流程中添加自动验证逻辑(加载 YAML 后、渲染前)
- [x] 7.3 实现验证失败时终止转换的逻辑
- [x] 7.4 确保 --no-check 选项可以跳过验证
## 8. 测试
- [x] 8.1 在 temp/ 目录创建测试用的 YAML 文件(包含各种错误场景)
- [x] 8.2 测试独立 check 命令的各种场景
- [x] 8.3 测试自动验证功能
- [x] 8.4 测试 --no-check 选项
- [x] 8.5 测试元素超出页面边界的检测
- [x] 8.6 测试图片文件不存在的检测
- [x] 8.7 测试模板文件验证
- [x] 8.8 测试颜色格式验证
- [x] 8.9 测试字体大小警告
- [x] 8.10 测试容忍度0.1 英寸)
## 9. 文档更新
- [x] 9.1 更新 README.md添加 check 命令的使用说明
- [x] 9.2 更新 README.md说明自动验证功能和 --no-check 选项
- [x] 9.3 添加验证错误码和消息的说明(如果需要)