feat: 实现 Pandoc DOCX 转换服务

This commit is contained in:
SkyJourney
2026-07-30 15:05:50 +08:00
parent fa159d916f
commit bf43433d38
32 changed files with 2908 additions and 61 deletions
+12 -3
View File
@@ -1,15 +1,17 @@
# @md-to-pdf/application
Web Server 与 Electron Desktop 共用的应用服务层,组合
`@md-to-pdf/core``@md-to-pdf/renderer`,统一处理 Markdown 渲染、
主题发现、主题资源和图片资源。Fastify 与 Electron IPC 只负责传输和
平台能力适配。
`@md-to-pdf/core``@md-to-pdf/renderer`
`@md-to-pdf/docx-engine`,统一处理 Markdown 渲染、主题发现、主题资源、
图片资源和 DOCX 导出编排。Fastify 与 Electron IPC 只负责传输和平台
能力适配。
## 目录结构
```text
src/
application-service.ts 渲染、主题和资源用例入口
docx-export-service.ts DOCX 并发、超时、错误和完整导出编排
docx-media-service.ts DOCX 媒体尺寸计算、PNG 校验与清单组装
image-resources.ts 本地、Base64 与受限远程图片处理
theme-registry.ts 内置及自定义主题扫描、校验与缓存
@@ -17,6 +19,7 @@ src/
tests/
application-service.test.ts
bundled-themes.test.ts
docx-export-service.test.ts
docx-media-service.test.ts
image-resources.test.ts
```
@@ -53,6 +56,12 @@ Desktop 才会以 Markdown 所在目录为边界解析相对资源。
大小、总大小和媒体 ID。最终按文档顺序输出稳定的 `media-001.png`
清单;它不依赖 Playwright 或 Electron,平台代码只负责 Chromium 捕获。
`DocxExportService` 串联 capability 探测、请求准备、平台媒体捕获、
Pandoc 转换和最终 OOXML 校验。默认并发为 1、队列为 4、总超时为 90 秒;
可以通过 `DOCX_CONCURRENCY``DOCX_MAX_QUEUE``DOCX_TIMEOUT_MS`
配置。排队、探测、准备、媒体、模板、Pandoc、校验和总耗时使用共享协议
返回;关闭服务时会取消活动任务、拒绝排队任务并等待清理完成。
内置主题来自仓库 `themes/`,当前名称为 Typora Github、
Typora Pixyll、Typora whitey 和 Typora Clean。额外主题从平台传入的
本地主题根目录扫描;与内置主题 ID 冲突时以内置主题为准。