Metadata-Version: 2.4
Name: doctyler
Version: 0.5.0
Summary: 多格式文档样式管理工具：提取、修改并重应用 Word/Typst/LaTeX 模板样式
Author: Doctyler Team
License-Expression: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: click>=8.0
Requires-Dist: python-docx>=0.8.11
Requires-Dist: python-pptx>=0.6.21
Requires-Dist: pyyaml>=6.0

# Doctyler v0.4.3

**Doctyler** 让文档样式可配置、可迁移。
内置 GB/T 9704 公文标准预设，支持 Word、Typst、LaTeX、ConTeXt、Quarto。

## 功能

- `doctyler docx init` – 初始化 Word 模板和配置
- `doctyler docx build` – 构建 reference 模板
- `doctyler docx extract` – 从 .docx 提取样式与页面设置
- `doctyler docx apply` – 用 JSON 配置反向修正 .docx 样式
- `doctyler pptx init` – 初始化 PowerPoint 模板和配置（基于 pandoc 默认）
- `doctyler pptx build` – 构建 GB/T 9704 主题模板
- `doctyler pptx extract` – 从 .pptx 提取主题色、字体、幻灯片尺寸
- `doctyler pptx apply` – 用 JSON 配置反向修正 .pptx 主题
- `doctyler docx dump` – 从 docx 提取样式 (JSON)
- `doctyler typst generate` – 生成 Typst 模板
- `doctyler typst extract` – 从 Typst 模板提取参数
- `doctyler typst apply` – 用配置更新 Typst 模板参数
- `doctyler latex generate` – 生成 LaTeX 文档骨架
- `doctyler latex extract` – 从 .cls 文件提取关键样式
- `doctyler latex apply` – 生成覆盖样式的 doctyler-custom.cls
- `doctyler context extract` – 从 ConTeXt 源文件提取配置
- `doctyler context apply` – 将配置应用到 ConTeXt 源文件
- `doctyler context generate` – 从配置生成 ConTeXt 环境文件
- `doctyler quarto generate` – 生成 .qmd 文件
- `doctyler filter list/create/show/use` – Lua 过滤器管理
- `doctyler extension create/use` – Quarto 扩展管理
- `doctyler diff-styles` – 从两个 docx 差异提取样式规则
- `doctyler copy` – 复制生成的模板到目标目录
- `doctyler config list/add/use/remove` – 配置版本管理

## 快速开始

```bash
pip install .
doctyler docx init
doctyler docx build
doctyler quarto generate --body-file content.md
```

## 样式迁移

```bash
# 从上级来文提取样式
doctyler docx extract incoming.docx -o style.json
# 修改 style.json 中一级标题字号
doctyler docx apply incoming.docx -c style.json -o fixed.docx
```

## 过滤器

```bash
# 列出可用过滤器
doctyler filter list
# 基于 title-promotion 创建新过滤器
doctyler filter create my-filter --based-on title-promotion
# 激活过滤器
doctyler filter use my-filter
```

## 扩展管理

```bash
# 创建 Quarto 扩展
doctyler extension create gbt9704
# 安装扩展到项目
doctyler extension use gbt9704
```

## 样式差异分析

```bash
# 比较两个 docx 的样式差异，生成规则
doctyler diff-styles base.docx styled.docx -o diff-rules.json
```

## 模板复制

```bash
# 复制所有模板到交付目录
doctyler copy --type all --target ./release --rename-with-version
# 仅复制 docx
doctyler copy --type docx --version gb9704 --target ../project
```

## 跨格式样式值解析

`units_ext` 模块自动处理多格式语义值，无需手工转换：

| 输入值 | 格式来源 | 解析结果 |
|---|---|---|
| `"2line"` | ConTeXt `\blank[2*line]` | 33.6pt |
| `"1.5"` | CSS 行距倍数 | 18pt |
| `"2em"` | CSS / ConTeXt 缩进 | 24pt |
| `"darkred"` | ConTeXt svg 颜色 | `8B0000` |
| `"C00000"` | OOXML 十六进制 | `C00000`（原样） |

支持 25 种命名颜色，ConTeXt 和 DOCX 配置可共用同一份 JSON。

## ConTeXt 样式提取

```bash
# 从 ConTeXt 环境文件提取样式
doctyler context extract src/doc-env.tex -o notes-style.json

# 生成 DOCX 模板（配置中的 ConTeXt 值自动转换）
doctyler docx init
cp notes-style.json doctyler-config.json
doctyler docx build

# 或用一键脚本
python scripts/extract_contex_style.py
```

详细指南见 `scripts/context-extract-guide.md`。

## 预设

| 预设 | 路径 | 用途 |
|---|---|---|
| gbt9704 | `presets/gbt9704/` | GB/T 9704 公文标准（Word/Typst/LaTeX） |
| gbt9704/pptx | `presets/gbt9704/pptx/` | GB/T 9704 公文标准（PowerPoint） |
| context-notes | `presets/context-notes/` | ConTeXt-notes 书籍风格 |
| pandoc-default | `presets/pandoc-default/` | pandoc 默认模板参考 |

## 许可

MIT
