release: 发布 v0.6.1 DOCX 视觉一致性修复

新增通用 CSS 到 OOXML 翻译修复,统一字体、字距、精确行距、段落、列表、表格、引用、代码块与行内代码连续性,不引入按主题 ID 分支。

新增 MdTP Mono 并统一 Serif、Sans、Mono 三字体包的 Chromium 与 DOCX 使用链;字体声明、嵌入部件和 Word/WPS 实际采用均进入硬门禁。

重建封面整页及正文语义块视觉差分,14 套主题、纵横两个方向、五组页边距共 140 个真实场景全部通过,阻断失败和诊断失败均为零。

源码服务、Docker Web API 与实际安装 Desktop 的 red-briefing 导出均包含 5 个字体部件;Word/WPS 原生渲染和逐页复核通过。修复 Docker 构建上下文与运行层复用软链接,并完善 v0.6.1 版本、发行说明和发布归集。

验证:npm test(116 个文件、616 项测试)、npm run typecheck、npm run build、git diff --check 全部通过。Desktop 安装器与 ZIP、Docker v0.6.1 镜像已生成;Windows 产物仍为未签名内部发行。
This commit is contained in:
SkyJourney
2026-08-04 10:30:44 +08:00
parent b275c671fc
commit 2c5c1bd317
84 changed files with 4404 additions and 344 deletions
File diff suppressed because it is too large Load Diff
+3 -2
View File
@@ -172,7 +172,7 @@ function pandocArguments(paths: {
return [
paths.markdown,
"--from",
"markdown+yaml_metadata_block+pipe_tables+footnotes+task_lists+tex_math_dollars",
"markdown+yaml_metadata_block+pipe_tables+footnotes+task_lists+tex_math_dollars-raw_html",
"--to",
"docx",
"--standalone",
@@ -375,7 +375,8 @@ export class PandocDocxConverter {
pandocDocx,
structurePlan,
input.themeTokens,
preparedMedia.layout
preparedMedia.layout,
preparedMedia.documentLayout
);
docx = embedFontsInGeneratedDocx(
finalized.content,
+8 -1
View File
@@ -6,6 +6,7 @@ import {
MAXIMUM_DOCX_RESOURCE_COUNT,
MAXIMUM_DOCX_TOTAL_MEDIA_BYTES,
type DocxMediaKind,
type DocxDocumentLayoutPlan,
type PreparedDocxMedia
} from "@md-to-pdf/core";
@@ -47,6 +48,7 @@ export interface PreparedPandocMedia {
map: PandocMediaMap;
files: PandocMediaFile[];
layout: PandocMediaLayoutItem[];
documentLayout: DocxDocumentLayoutPlan;
}
export const DOCX_MEDIA_BINDING_PREFIX = "mdtp-media:";
@@ -184,5 +186,10 @@ export function preparePandocMedia(
if (media.totalBytes !== totalBytes) {
throw new Error("DOCX 媒体总大小声明不一致");
}
return { map, files, layout };
return {
map,
files,
layout,
documentLayout: media.documentLayout ?? { tables: [] }
};
}
@@ -69,9 +69,17 @@ const containerRoles = new Set<SemanticDocumentRole>([
"tender-cover"
]);
const semanticRoleSlotAliases: Readonly<
Partial<Record<SemanticDocumentRole, DocxStyleSlotName>>
> = {};
function slotName(
role: SemanticDocumentRole
): DocxStyleSlotName | undefined {
const alias = semanticRoleSlotAliases[role];
if (alias) {
return alias;
}
return Object.prototype.hasOwnProperty.call(
DOCX_SLOT_WORD_STYLE_BINDINGS,
role
+94 -8
View File
@@ -7,8 +7,10 @@ import type {
import type { ResolvedDocxThemeStyle } from "./style-presets.js";
import {
DOCX_SLOT_WORD_STYLE_BINDINGS,
PANDOC_SYNTAX_STYLE_IDS,
collectDocxTokenFonts,
createDocxTokenSlotMap,
resolvePandocSyntaxStyleSlot,
resolveTokenFonts
} from "./token-style-map.js";
import {
@@ -64,7 +66,8 @@ function setRunStyle(
"iCs",
"u",
"shd",
"spacing"
"spacing",
"kern"
);
if (options.fonts) {
setFonts(parent, options.fonts);
@@ -106,6 +109,9 @@ function setRunStyle(
"w:val": wordCharacterSpacingTwips(options.sizePt)
});
}
appendElement(parent, WORD_NAMESPACE, "w:kern", {
"w:val": "2"
});
}
function setParagraphSpacing(
@@ -200,8 +206,16 @@ function fallbackFontsForSlot(
if (slot.startsWith("heading-") || slot.endsWith("-title")) {
return fallback.headings.fonts;
}
if (slot === "inline-code" || slot === "code-block") {
return fallback.code.fonts;
if (
slot === "inline-code" ||
slot === "code-block" ||
slot === "code-block-text" ||
slot.startsWith("code-token-")
) {
return {
...fallback.code.fonts,
eastAsia: fallback.body.fonts.eastAsia
};
}
if (
slot === "table" ||
@@ -232,7 +246,12 @@ function fallbackFontSizeForSlot(
if (slot.endsWith("-title")) {
return fallback.headings.sizesPt[0];
}
if (slot === "inline-code" || slot === "code-block") {
if (
slot === "inline-code" ||
slot === "code-block" ||
slot === "code-block-text" ||
slot.startsWith("code-token-")
) {
return fallback.code.sizePt;
}
if (
@@ -251,10 +270,17 @@ function fallbackFontSizeForSlot(
function applyTokenRunStyle(
parent: XmlElement,
token: DocxSlotStyleToken,
fallbackFonts: DocxFontFamily
fallbackFonts: DocxFontFamily,
preserveFallbackEastAsia = false
) {
removeDirectChildren(parent, WORD_NAMESPACE, "kern");
appendElement(parent, WORD_NAMESPACE, "w:kern", {
"w:val": "2"
});
if (token.fontCandidates.length) {
setFonts(parent, resolveTokenFonts(token, fallbackFonts));
setFonts(parent, resolveTokenFonts(token, fallbackFonts, {
preserveFallbackEastAsia
}));
}
if (token.fontSizePt !== undefined) {
removeDirectChildren(parent, WORD_NAMESPACE, "sz", "szCs");
@@ -1176,17 +1202,77 @@ function applyTokenStyles(
binding.styleId === "SourceCode"
);
}
const runToken = binding.styleId === "SourceCode"
? slots.get("code-block-text")?.style ?? entry.style
: entry.style;
applyTokenRunStyle(
ensureDirectElement(
target,
WORD_NAMESPACE,
"w:rPr"
),
entry.style,
fallbackFontsForSlot(slot, fallback)
runToken,
fallbackFontsForSlot(slot, fallback),
binding.styleId === "SourceCode" ||
slot === "inline-code" ||
slot === "code-block" ||
slot === "code-block-text" ||
slot.startsWith("code-token-")
);
}
}
const codeTextToken =
slots.get("code-block-text")?.style ??
slots.get("code-block")?.style;
if (codeTextToken) {
const baseStyleId = "MdSourceCodeChar";
const baseStyle = ensureStyle(
styles,
baseStyleId,
"character",
"BodyTextChar"
);
applyTokenRunStyle(
ensureDirectElement(baseStyle, WORD_NAMESPACE, "w:rPr"),
codeTextToken,
{
...fallback.code.fonts,
eastAsia: fallback.body.fonts.eastAsia
},
true
);
for (const styleId of PANDOC_SYNTAX_STYLE_IDS) {
const target = ensureStyle(
styles,
styleId,
"character",
baseStyleId
);
const basedOn = firstDirectChild(
target,
WORD_NAMESPACE,
"basedOn"
);
if (basedOn) {
setWordAttribute(basedOn, "val", baseStyleId);
}
const syntaxSlot = resolvePandocSyntaxStyleSlot(styleId);
const syntaxToken = syntaxSlot
? slots.get(syntaxSlot)?.style
: undefined;
if (syntaxToken) {
applyTokenRunStyle(
ensureDirectElement(target, WORD_NAMESPACE, "w:rPr"),
syntaxToken,
{
...fallback.code.fonts,
eastAsia: fallback.body.fonts.eastAsia
},
true
);
}
}
}
applyTableTokenStyles(styles, slots, fallback);
}
+93 -2
View File
@@ -110,6 +110,7 @@ export const DOCX_SLOT_WORD_STYLE_BINDINGS: Readonly<
paragraph("MdOfficialPrintingRow")
],
"briefing-masthead": [paragraph("MdBriefingMasthead")],
"briefing-masthead-text": [paragraph("MdBriefingMastheadText")],
"briefing-meta": [paragraph("MdBriefingMeta")],
"briefing-title": [paragraph("MdBriefingTitle")],
"briefing-contact": [paragraph("MdBriefingContact")],
@@ -141,6 +142,93 @@ export const DOCX_SLOT_WORD_STYLE_BINDINGS: Readonly<
"tender-date": [paragraph("MdTenderDate")]
};
export const PANDOC_SYNTAX_STYLE_IDS = [
"AlertTok",
"AnnotationTok",
"AttributeTok",
"BaseNTok",
"BuiltInTok",
"CharTok",
"CommentTok",
"CommentVarTok",
"ConstantTok",
"ControlFlowTok",
"DataTypeTok",
"DecValTok",
"DocumentationTok",
"ErrorTok",
"ExtensionTok",
"FloatTok",
"FunctionTok",
"ImportTok",
"InformationTok",
"KeywordTok",
"NormalTok",
"OperatorTok",
"OtherTok",
"PreprocessorTok",
"SpecialCharTok",
"SpecialStringTok",
"StringTok",
"VariableTok",
"VerbatimStringTok",
"WarningTok"
] as const;
const pandocSyntaxSlots: Readonly<
Partial<Record<(typeof PANDOC_SYNTAX_STYLE_IDS)[number], DocxStyleSlotName>>
> = {
AlertTok: "code-token-keyword",
AnnotationTok: "code-token-comment",
AttributeTok: "code-token-attribute",
BaseNTok: "code-token-number",
BuiltInTok: "code-token-built-in",
CharTok: "code-token-string",
CommentTok: "code-token-comment",
CommentVarTok: "code-token-comment",
ConstantTok: "code-token-literal",
ControlFlowTok: "code-token-keyword",
DataTypeTok: "code-token-attribute",
DecValTok: "code-token-number",
DocumentationTok: "code-token-comment",
ErrorTok: "code-token-keyword",
ExtensionTok: "code-token-built-in",
FloatTok: "code-token-number",
FunctionTok: "code-token-title",
ImportTok: "code-token-keyword",
InformationTok: "code-token-comment",
KeywordTok: "code-token-keyword",
OperatorTok: "code-token-operator",
PreprocessorTok: "code-token-meta",
SpecialCharTok: "code-token-string",
SpecialStringTok: "code-token-string",
StringTok: "code-token-string",
VariableTok: "code-token-variable",
VerbatimStringTok: "code-token-string",
WarningTok: "code-token-keyword"
};
export function resolvePandocSyntaxStyleSlot(
styleId: string,
text = ""
): DocxStyleSlotName | "code-block-text" | undefined {
if (!(PANDOC_SYNTAX_STYLE_IDS as readonly string[]).includes(styleId)) {
return undefined;
}
if (
styleId === "NormalTok" ||
styleId === "OtherTok" ||
(styleId === "FunctionTok" && /^[\p{P}\p{S}\s]+$/u.test(text))
) {
return styleId === "FunctionTok"
? "code-token-punctuation"
: "code-block-text";
}
return pandocSyntaxSlots[
styleId as (typeof PANDOC_SYNTAX_STYLE_IDS)[number]
] ?? "code-block-text";
}
const eastAsiaFontPattern =
/(?:fandol|yahei|simsun|simhei|fangsong|kaiti|dengxian|cjk|source\s+han|pingfang|heiti|songti|||仿||线)/iu;
const genericFontNames = new Set([
@@ -154,7 +242,8 @@ const genericFontNames = new Set([
export function resolveTokenFonts(
token: DocxSlotStyleToken | undefined,
fallback: DocxFontFamily
fallback: DocxFontFamily,
options: { preserveFallbackEastAsia?: boolean } = {}
): DocxFontFamily {
const candidates = (token?.fontCandidates ?? []).filter(
(candidate) =>
@@ -166,7 +255,9 @@ export function resolveTokenFonts(
const eastAsia =
candidates.find((candidate) =>
eastAsiaFontPattern.test(candidate)
) ?? candidates[0]!;
) ?? (options.preserveFallbackEastAsia
? fallback.eastAsia
: candidates[0]!);
const latin =
candidates.find(
(candidate) => !eastAsiaFontPattern.test(candidate)