Repository navigation
fix(docx): 独立图片居中 + 标题黑体(中文排版规范) - #22
Merged
Merged
Conversation
This was referenced Sep 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更概述
fix(docx): 独立图片居中 + 标题黑体(中文排版规范)
修复 issue #21 —— docx 导出(
render --format docx/ 浏览器toDocx)两项排版缺陷:<w:jc w:val="center"/>。<w:rFonts w:eastAsia="黑体"/>,正文 docDefaults 保持宋体。关联 Issue
Closes #21
变更内容
packages/mdpkg/src/docx.tsSTYLES_XML的 Heading1–6<w:rPr>各注入<w:rFonts w:eastAsia="黑体"/>(仅覆盖 eastAsia,ascii/hAnsi 仍继承 Calibri);②blockToXmlparagraph 分支新增isStandaloneImage判定并注入<w:jc w:val="center"/>packages/mdpkg/test/docx.test.tsw:jc/ 行内图片不含 / 表格单元格图片不含 / Heading1–6 各含eastAsia="黑体"(并计数=6)/ docDefaults 仍为宋体packages/mdpkg/web/mdpkg-web.js、web/mdpkg-web.iife.jsnpm run build:web重建(未手改).omo/notepads/docx-export-quality/learnings.md居中判定条件(仅同时满足才居中):段落唯一子节点为
image,且extra无style、无numPr。据此排除:行内图片(段落含文本)、表格单元格(style:'Table')、列表项(numPr)、引用块(style:'Quote')、callout(走splitCalloutHead路径不进入该分支)。影响范围
src/docx.ts序列化层(样式表 + 段落对齐)。HTML 渲染路径(render.ts)零改动。toDocx(files, opts, onWarning?)签名、CLI 形态、MdeError/onWarning契约、SVG/缺失资源降级行为、docDefaults(正文宋体)均不变。<w:pPr>输出逐字节不变(centerJc为空串时allPPr === pPr)。验证方式
cd packages/mdpkg && npm test→ 323/323 pass(318 既有零回归 + 5 新增)npm run build:web重建幂等(重建后与提交产物 sha256 一致)unzip -p断言:word/document.xml:独立图片段落恰好 1 处<w:jc w:val="center"/>;同文档表格单元格内图片 0 处word/styles.xml:eastAsia="黑体"6 处(Heading1–6);docDefaults仍eastAsia="宋体"1 处code-review双轴(Standards + Spec):APPROVE / APPROVE,零缺陷复现命令
规格核查(用户问题 2 的结论)
现无任何受版本控制的规格规定标题字体或图片对齐——
openspec/specs/docx-export/spec.md三节 Requirement 均未提及字体与图片对齐,实现侧docDefaults = Calibri + eastAsia 宋体与计划plans/mdpkg-docx-export-capability.md一致。属规格空缺(spec gap),非实现违反规格。本 PR 已在本地 openspec 补齐能力域 Requirement「docx 排版规范」(含 5 个 Scenario,
openspec validate --strict通过):风险评估
风险等级: low
来源: ai-generated
黑体(SimHei)在未安装该字体的阅读器中会走系统回退,属字体可用性问题,非实现缺陷。回滚方案
git revert 即可回滚