Files
html2pptx/README.md
T

96 lines
2.9 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.
# html2pptx
HTML / 截图 → 标准 JSON → 可编辑 PPTX
将任何格式的演示文稿描述转化为**文字可编辑、布局可还原**的 PPTX 文件。
## 架构
```
输入(任意来源) 中间层 输出
━━━━━━━━━━━━━━━ ━━━━━━━━━━━ ━━━━━
AI 生成的描述 标准 JSON PPTX 文件
HTML 提取的结构 → Schema 校验 → pptxgenjs 渲染
多模态识别结果 ↓
Markdown / 其他 翻译引擎(机械映射)
```
### 三层结构
| 层 | 目录 | 说明 |
|---|------|------|
| **知识库** | `reference/` | pptxgenjs 完整参数表,每个参数的类型/取值范围/默认值。给 AI 用的操作手册 |
| **Schema** | `schema/` | JSON Schema 定义 + 示例。AI 输出符合此 Schema 的 JSON 即可驱动 PPT 生成 |
| **翻译引擎** | `renderer/` | JSON → pptxgenjs API 调用的机械映射。不做逻辑判断,只做参数透传 |
## 快速开始
```bash
npm install
```
### 从 JSON 生成 PPTX
```javascript
const { render } = require('./renderer/index');
const pptx = render(jsonObject);
pptx.writeFile({ fileName: 'output.pptx' });
```
### 从 JSON 文件生成
```javascript
const { renderFile } = require('./renderer/index');
renderFile('./schema/examples/ui-dashboard.json', 'output.pptx');
```
## 目录结构
```
reference/ ← 知识库:每个元素的完整参数表
text.md 文字参数
shape.md 形状参数
table.md 表格参数
image.md 图片参数
chart.md 图表参数
slide.md 页面参数
master.md 母版参数
output.md 输出参数
coordinate.md 坐标换算
schema/ ← JSON Schema 定义
presentation.schema.json
examples/
basic.json 基础示例(2页)
full.json 全功能示例
ui-dashboard.json UI 看板示例
ui-advanced.json 精细化 UI 示例
renderer/ ← 翻译引擎
index.js 主入口
text-renderer.js 文字渲染
shape-renderer.js 形状渲染
table-renderer.js 表格渲染
image-renderer.js 图片渲染
chart-renderer.js 图表渲染
slide-renderer.js 页面属性
PPTXGENJS_API.md ← pptxgenjs v4.0.1 完整 API 参考
```
## 设计原则
- **翻译引擎是纯机械映射** — 不做样式推断,不做逻辑判断。JSON 里有什么就画什么
- **Schema 是 AI 友好** — 字段名直观,不暴露 pptxgenjs 内部命名
- **知识库是完整参考** — 每个参数都有类型+取值范围+默认值,不需要 AI 去猜
## 依赖
| 包 | 用途 |
|---|------|
| pptxgenjs | 生成 PPTX 文件(OOXML |
## License
MIT