Markdown to docx

From findscripter/everything-skills · View interactive version

Markdown to docx is an AI agent skill from the GitHub repository findscripter/everything-skills. 当需要把 Markdown 转换成 .docx(保留标题/表格/样式)、生成可交付 Word 文档时使用;触发词:md 转 word、导出 docx、Markdown 转 Word、Pandoc。

How to use this skill

Skill file

何时使用

不该用的边界:

步骤 / 指令

  1. 确认输入:定位源 .md 文件绝对路径;确认输出 .docx 目标路径。
  2. 检查工具链:运行 pandoc --version;缺失则提示安装(Windows:winget install --id JohnMacFarlane.Pandoc)。
  3. 基础转换:

```

pandoc <input.md> -o <output.docx>

```

  1. 需要套样式时,先准备参考文档(一次性生成可编辑模板):

```

pandoc -o reference.docx --print-default-data-file reference.docx

```

在 Word 中改好样式后保存,再用 --reference-doc=reference.docx 应用。

  1. 处理表格/资源:含 GFM 表格或脚注时加 -f gfm;图片用相对路径并加 --resource-path=<dir>。
  2. 校验产物:确认 .docx 存在且体积非 0,必要时回读确认标题与表格未丢失,再交付绝对路径。

伪代码:

assert exists(input_md)
if not has("pandoc"): tell_user_install(); stop
cmd = ["pandoc", input_md, "-o", output_docx]
if needs_template: cmd += ["--reference-doc", reference_docx]
if has_gfm_tables: cmd = ["pandoc","-f","gfm", input_md, "-o", output_docx, ...]
run(cmd); verify(output_docx)

示例

最小可用(基础转换):

pandoc report.md -o report.docx

带模板 + GFM 表格 + 目录:

pandoc -f gfm --reference-doc=corp-template.docx --toc report.md -o report.docx

提示词示例(交给 Agent 时):

把 E:\docs\周报.md 转成 E:\out\周报.docx,套用 E:\tpl\公司模板.docx,保留所有表格。

注意事项

互见

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.