pandoc-docx

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Pandoc Docx

Pandoc Docx

Prerequisites

前置条件

Ensure Pandoc is installed:
bash
pandoc --version
确保已安装Pandoc:
bash
pandoc --version

If not installed: brew install pandoc (macOS) or apt-get install pandoc (Linux)

如果未安装:macOS使用 brew install pandoc,Linux使用 apt-get install pandoc

undefined
undefined

Directory Setup

目录设置

Create working directories in your project root:
bash
mkdir -p import export
  • import/
    - Source files to convert
  • export/
    - Converted output files
在项目根目录创建工作目录:
bash
mkdir -p import export
  • import/
    - 待转换的源文件
  • export/
    - 转换后的输出文件

Convert to DOCX

转换为DOCX

Basic conversion:
bash
pandoc import/input.md -o export/output.docx
Common options:
  • --reference-doc=template.docx
    - Apply custom styling
  • --toc
    - Generate table of contents
  • --toc-depth=2
    - Set TOC depth
  • --metadata="title=My Document"
    - Set document metadata
Use skill's Chinese template:
bash
undefined
基础转换命令:
bash
pandoc import/input.md -o export/output.docx
常用选项:
  • --reference-doc=template.docx
    - 应用自定义样式
  • --toc
    - 生成目录
  • --toc-depth=2
    - 设置目录层级
  • --metadata="title=My Document"
    - 设置文档元数据
使用技能的中文模板:
bash
undefined

Path depends on where skill is installed:

路径取决于技能的安装位置:

- Project local: .agents/skills/pandoc-docx/ (or your skill installation path)

- 项目本地:.agents/skills/pandoc-docx/(或你的技能安装路径)

- Global: ~/.config/skills/pandoc-docx/ (varies by OS and tool)

- 全局:~/.config/skills/pandoc-docx/(因操作系统和工具而异)

pandoc import/input.md -o export/output.docx
--reference-doc=<skill-path>/assets/templates.docx
undefined
pandoc import/input.md -o export/output.docx
--reference-doc=<skill-path>/assets/templates.docx
undefined

Convert from DOCX

从DOCX转换为其他格式

bash
pandoc import/document.docx -o export/document.md --extract-media=export/images/
bash
pandoc import/document.docx -o export/document.md --extract-media=export/images/

Custom Templates

自定义模板

  1. Generate default template:
    pandoc --print-default-data-file reference.docx > reference.docx
  2. Edit styles in Word
  3. Apply:
    pandoc import/input.md -o export/output.docx --reference-doc=reference.docx
  1. 生成默认模板:
    pandoc --print-default-data-file reference.docx > reference.docx
  2. 在Word中编辑样式
  3. 应用模板:
    pandoc import/input.md -o export/output.docx --reference-doc=reference.docx

Batch Processing

批量处理

bash
SKILL_PATH="<skill-path>"  # Adjust to your skill installation path

for file in import/*.md; do
  pandoc "$file" -o "export/$(basename "${file%.md}").docx" \
    --reference-doc=$SKILL_PATH/assets/templates.docx
done
bash
SKILL_PATH="<skill-path>"  # 根据你的技能安装路径调整

for file in import/*.md; do
  pandoc "$file" -o "export/$(basename "${file%.md}").docx" \
    --reference-doc=$SKILL_PATH/assets/templates.docx
done

Resources

资源

  • assets/templates.docx - Chinese DOCX template with title numbering and code highlighting
  • scripts/convert.sh - Helper script for conversions (see usage below)
  • references/pandoc-options.md - Complete option reference and advanced patterns
  • assets/templates.docx - 包含标题编号和代码高亮的中文DOCX模板
  • scripts/convert.sh - 转换辅助脚本(使用方法如下)
  • references/pandoc-options.md - 完整选项参考与进阶用法

Using convert.sh

使用convert.sh

bash
undefined
bash
undefined

Run from project root. Adjust <skill-path> to where skill is installed:

从项目根目录运行。根据技能安装路径调整<skill-path>

<skill-path>/scripts/convert.sh report.md report.docx
<skill-path>/scripts/convert.sh report.md report.docx

With options

带选项使用

<skill-path>/scripts/convert.sh report.md report.docx --toc
<skill-path>/scripts/convert.sh report.md report.docx --toc

Absolute paths work as usual

绝对路径同样适用

<skill-path>/scripts/convert.sh /path/to/input.md /path/to/output.docx
undefined
<skill-path>/scripts/convert.sh /path/to/input.md /path/to/output.docx
undefined