Skip to content

[bug] docx 导出 8 项缺陷:图片空白/编号连续/行距 1.5/表格排版/callout 标识/移动端表格变文本 #9

Closed

Description

@lqtdys

问题描述

用户反馈 docx 导出(render --format docx / mdpkg-web toDocx)存在 8 项缺陷:

  1. 图片不显示:有占位空间但显示空白(位图未实际嵌入)
  2. 自动编号:小数字编号 1. 2. 是全文档连续编号,未按列表独立编号(第二、三个有序列表接续前列表计数)
  3. 行距:当前 1.5 倍行距,应改为单倍
  4. 表格文字无故换行:单元格内文字即使宽度满足也换行
  5. 表格宽度不齐:部分表格不满宽、靠左显示,不同表格宽度不同
  6. 单元格内边距:文字贴近边线无边距,应上下居中、左右留边距
  7. callout 标识残留:callout/代码等 Markdown 特有格式导出后带 [!tip] 等文字标识,应去除并按原格式背景色显示
  8. 移动端导出表格变文本:md-bundle 网页端(vendored mdpkg-web.js 过期)导出 docx 时表格显示为 Markdown 管道文本

期望行为

  • 位图正常嵌入并显示
  • 每个有序列表独立从 1 编号
  • 单倍行距
  • 表格满宽、单元格文字不无故换行、有内边距且垂直居中
  • callout 去除标识、按类型背景色显示
  • 移动端(浏览器)导出与 CLI 一致的 docx

复现步骤

样例一:CLI 导出 render --format docx 处理 /Users/mason/Downloads/0测试资料/V8-5.6考试-skill(1)/SKILL.md(含多张表格、多个有序列表、blockquote)→ SKILL.docx
样例二:md-bundle 网页端导出 /Users/mason/Downloads/callout-table.md → callout-table.docx(表格成管道文本、[!tip]/[!warning]/[!info] 标识残留、\n 原样在 w:t 内)

根因分析(已验证)

  1. docx.ts imageToXml:image 关系 Target 写成 word/media/img-1.png,而 document.xml.rels 相对基准是 word/,实际解析为 word/word/media/… → 空白占位
  2. 所有 ol 共用 numId=2(numbering.xml 单一实例),Word 计数器跨列表连续
  3. STYLES_XML docDefaults w:line=360(auto=1.5 倍)
  4. textToRuns 把软换行 \n 转 w:br 硬换行(HTML 语义为空格)+ 表格 tblW auto 布局
  5. tblW w=0 type=auto 无 fixed 布局
  6. tcPr 无 tblCellMar / vAlign
  7. blockquote 未识别 Obsidian callout 语法(> [!type] 标题)
  8. md-bundle apps/web/vendor/mdpkg-web.js(构建于 9/12,非当前 src 9/13)+ 线上旧部署:表格无 w:tbl、无 GFM 表格调用,callout 仅左边框无标识剥离

修复方案

  1. image rels Target 改为相对 word/ 的 media/img-1.png
  2. 每个 ol 分配独立 numId(numbering.xml 动态生成 num 实例 + lvlOverride 支持 start)
  3. line 360 → 240
  4. 软换行 \n → 空格(与 HTML 路径一致);break 节点仍 w:br
  5. tblW w=9026 type=dxa(页宽 11906-1440x2)+ tblLayout fixed + tblGrid 均分
  6. tblCellMar(上/下 57、左/右 108 dxa)+ vAlign center
  7. blockquote 首行匹配 [!TYPE]:剥离标识、标题加粗、按类型映射背景色(note 蓝/tip 绿/warning 黄/danger 红/example 紫/quote 灰等)
  8. 修复后 build:web 重建 bundle 同步 md-bundle vendor(md-bundle AGENTS.md:vendor 为 byte-identical 上游拷贝)

来源: 聊天反馈
模块: module-b
优先级: P1

Activity

  1. added
    bug
    needs-triage
    module-b
    p1
    ready-for-agent
    and removed
    needs-triage
    on Sep 14, 2026
  2. lqtdys commented on Sep 14, 2026

    @lqtdys
    CollaboratorAuthor

    triage 验证通过:已用两个真实样例解包(SKILL.docx 47836B / callout-table.docx 5121B)逐一确认 8 项根因(详见 issue 正文)。修复方案明确,标记 ready-for-agent,开始 fix 线。

  3. lqtdys commented on Sep 14, 2026

    @lqtdys
    CollaboratorAuthor

    已修复并合并(PR #10,commit 03e7a64):

    验证结果(全部通过):

    • 全量测试 291/291(docx 65 项,含 15 项新增回归)
    • 真实样例端到端:SKILL.md(7 表格满宽/4 个列表独立编号/无标识残留)+ callout-table.md(callout 标题加粗、正文正常、表格 w:tbl)→ textutil 打开验证
    • 修复后样例:/Users/mason/Downloads/SKILL-fixed.docx、/Users/mason/Downloads/callout-table-fixed.docx

    8 项修复落地:

    1. 图片 rels Target 相对 word/ → 不再空白
    2. 每列表独立 numId 实例 + lvlOverride 起始号
    3. docDefaults line=240 单倍行距
    4. 软换行并入空格(硬换行保留 w:br)
    5. tblW 9026 dxa + fixed 布局满宽
    6. tblCellMar 内边距 + vAlign center
    7. callout 去 [!type] 标识、按类型背景色、标题加粗;代码块 [lang] 标注移除
    8. web bundle 已重建(md-bundle vendor 更新待同步)

    待办:md-bundle 仓库同步新 bundle(apps/web/vendor/mdpkg-web.js)+ 重新部署后,移动端导出表格恢复正常。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmodule-bp1ready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions