新增能力:将 DOCX 发布验收拆分为四套独立 140,支持真实语料冻结、指纹复用、失败与基础设施错误独立统计,并为表格换行、全 JSON 围栏、代码连续性和长文档分页建立通用门禁。 问题修复:冻结 Paged.js 分片前的逻辑表格列轨并传递打印几何,统一 Markdown 表格换行、代码、段落与 OOXML 翻译;改进 PDF 文本流排序、语义块映射、颜色与栅格比较,消除窄字符重叠和跨行范围符号误报。 兼容与部署:版本统一为 0.6.2;正式 Docker 镜像内置固定 Chromium、Pandoc 3.9.0.2 和 Serif/Sans/Mono 字体;Desktop NSIS 与 ZIP 继续直接内置字体,无需系统字体安装。 验证结果:合成基线与长庆严格 280/280,M4N 140/140;健康数据残余误报 6/115(5.22%),均核查为重复表头自动对齐/取样误报且基础设施错误为 0。全项目测试、类型检查、生产构建和 git diff --check 通过;正式 Docker、NSIS、ZIP、离线镜像、部署包、清单及 SHA-256 均已生成并校验。
120 lines
3.2 KiB
TypeScript
120 lines
3.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { DocxThemeTokenSet } from "@md-to-pdf/docx-theme-engine";
|
|
import {
|
|
DOCX_SLOT_WORD_STYLE_BINDINGS,
|
|
collectDocxTokenFonts,
|
|
createDocxTokenSlotMap,
|
|
resolvePandocSyntaxStyleSlot,
|
|
resolveTokenFonts
|
|
} from "../src/index.js";
|
|
|
|
const tokens: DocxThemeTokenSet = {
|
|
schemaVersion: 1,
|
|
themeId: "test-theme",
|
|
themeFingerprint: "a".repeat(64),
|
|
mode: "auto",
|
|
basePreset: "general",
|
|
slots: [
|
|
{
|
|
slot: "paragraph",
|
|
source: "computed-css",
|
|
confidence: "exact",
|
|
style: {
|
|
fontCandidates: [
|
|
"Source Han Serif SC",
|
|
"Times New Roman",
|
|
"serif"
|
|
]
|
|
}
|
|
}
|
|
],
|
|
diagnostics: []
|
|
};
|
|
|
|
describe("DOCX 令牌样式映射", () => {
|
|
it("以稳定样式 ID 覆盖标准 Markdown 和结构槽位", () => {
|
|
expect(
|
|
DOCX_SLOT_WORD_STYLE_BINDINGS["heading-1"]
|
|
).toEqual([
|
|
{
|
|
styleId: "Heading1",
|
|
type: "paragraph",
|
|
basedOn: "Normal"
|
|
},
|
|
{
|
|
styleId: "Heading1Char",
|
|
type: "character",
|
|
basedOn: "DefaultParagraphFont"
|
|
}
|
|
]);
|
|
expect(
|
|
DOCX_SLOT_WORD_STYLE_BINDINGS["official-title"]?.[0]
|
|
?.styleId
|
|
).toBe("MdOfficialTitle");
|
|
expect(
|
|
DOCX_SLOT_WORD_STYLE_BINDINGS["tender-representative"]?.[0]
|
|
?.styleId
|
|
).toBe("MdTenderRepresentative");
|
|
});
|
|
|
|
it("按文字系统选择字体并过滤 CSS 通用族名", () => {
|
|
const slot = createDocxTokenSlotMap(tokens).get("paragraph");
|
|
expect(
|
|
resolveTokenFonts(slot?.style, {
|
|
latin: "Arial",
|
|
eastAsia: "SimSun"
|
|
})
|
|
).toEqual({
|
|
latin: "Times New Roman",
|
|
eastAsia: "Source Han Serif SC",
|
|
complexScript: "Times New Roman"
|
|
});
|
|
expect([...collectDocxTokenFonts(tokens)]).toEqual([
|
|
"Source Han Serif SC",
|
|
"Times New Roman"
|
|
]);
|
|
expect(
|
|
resolveTokenFonts(
|
|
{ fontCandidates: ["MdTP Mono", "monospace"] },
|
|
{ latin: "Arial", eastAsia: "MdTP Sans SC" },
|
|
{ preserveFallbackEastAsia: true }
|
|
)
|
|
).toEqual({
|
|
latin: "MdTP Mono",
|
|
eastAsia: "MdTP Sans SC",
|
|
complexScript: "MdTP Mono"
|
|
});
|
|
});
|
|
|
|
it("将 Pandoc 语法样式映射到引擎级代码语义槽位", () => {
|
|
expect(resolvePandocSyntaxStyleSlot("DataTypeTok", '"key"'))
|
|
.toBe("code-token-attribute");
|
|
expect(resolvePandocSyntaxStyleSlot("DataTypeTok", "<"))
|
|
.toBe("code-token-punctuation");
|
|
expect(
|
|
resolvePandocSyntaxStyleSlot(
|
|
"KeywordTok",
|
|
"section",
|
|
{ htmlTagName: true }
|
|
)
|
|
).toBe("code-token-name");
|
|
expect(resolvePandocSyntaxStyleSlot("StringTok", '"value"'))
|
|
.toBe("code-token-string");
|
|
expect(resolvePandocSyntaxStyleSlot("FunctionTok", ":"))
|
|
.toBe("code-token-punctuation");
|
|
expect(resolvePandocSyntaxStyleSlot("FunctionTok", "render"))
|
|
.toBe("code-token-title");
|
|
expect(resolvePandocSyntaxStyleSlot("NormalTok", " "))
|
|
.toBe("code-block-text");
|
|
expect(
|
|
resolvePandocSyntaxStyleSlot(
|
|
"NormalTok",
|
|
" method",
|
|
{ objectPropertyKey: true }
|
|
)
|
|
).toBe("code-token-attribute");
|
|
expect(resolvePandocSyntaxStyleSlot("UnknownTok", "x"))
|
|
.toBeUndefined();
|
|
});
|
|
});
|