markdown-to-docx
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMarkdown to DOCX Converter
Markdown转DOCX转换器
Overview
概述
Convert Markdown files to Microsoft Word DOCX format using the npm package. Supports single file and batch conversions with automatic output file naming.
markdown-docx使用 npm包将Markdown文件转换为Microsoft Word DOCX格式。支持单文件和批量转换,并可自动生成输出文件名。
markdown-docxQuick Start
快速开始
Single file conversion:
bash
python scripts/convert_md_to_docx.py -i document.mdThis creates in the same directory.
document.docxBatch conversion:
bash
python scripts/convert_md_to_docx.py -i file1.md file2.md file3.mdEach file is converted to DOCX in its original location.
Custom output location:
bash
python scripts/convert_md_to_docx.py -i document.md -o output/mydoc.docxBatch to specific directory:
bash
python scripts/convert_md_to_docx.py -i *.md -o output_docs/单文件转换:
bash
python scripts/convert_md_to_docx.py -i document.md这会在同一目录下生成。
document.docx批量转换:
bash
python scripts/convert_md_to_docx.py -i file1.md file2.md file3.md每个文件都会在原位置转换为DOCX格式。
自定义输出位置:
bash
python scripts/convert_md_to_docx.py -i document.md -o output/mydoc.docx批量转换到指定目录:
bash
python scripts/convert_md_to_docx.py -i *.md -o output_docs/Workflow
工作流程
When a user requests markdown to DOCX conversion:
- Identify input files - Confirm which markdown file(s) to convert
- Determine output naming - Use auto-naming unless user specifies custom names
- Run conversion - Execute the script with appropriate parameters
- Report results - Inform user of success and output file location(s)
当用户请求将Markdown转换为DOCX时:
- 识别输入文件 - 确认要转换的Markdown文件
- 确定输出命名 - 除非用户指定自定义名称,否则使用自动命名
- 执行转换 - 使用适当的参数运行脚本
- 报告结果 - 告知用户转换成功及输出文件位置
Common Use Cases
常见使用场景
Convert a single markdown file
转换单个Markdown文件
User: "Convert README.md to DOCX"
bash
python scripts/convert_md_to_docx.py -i README.md用户:"将README.md转换为DOCX"
bash
python scripts/convert_md_to_docx.py -i README.mdConvert all markdown files in current directory
转换当前目录下所有Markdown文件
User: "Convert all my markdown files to Word documents"
bash
python scripts/convert_md_to_docx.py -i *.md用户:"将我所有的Markdown文件转换为Word文档"
bash
python scripts/convert_md_to_docx.py -i *.mdConvert with custom output name
自定义输出文件名转换
User: "Convert notes.md to report.docx"
bash
python scripts/convert_md_to_docx.py -i notes.md -o report.docx用户:"将notes.md转换为report.docx"
bash
python scripts/convert_md_to_docx.py -i notes.md -o report.docxConvert documentation set to a folder
将文档集转换到指定文件夹
User: "Convert all docs to DOCX and put them in the exports folder"
bash
python scripts/convert_md_to_docx.py -i docs/*.md -o exports/用户:"将所有文档转换为DOCX并放入exports文件夹"
bash
python scripts/convert_md_to_docx.py -i docs/*.md -o exports/Script Details
脚本详情
Location:
scripts/convert_md_to_docx.pyFeatures:
- Validates input files exist and are markdown format
- Auto-generates output filenames (input.md → input.docx)
- Supports custom output paths for single files
- Supports output directory for batch conversions
- Creates output directories if they don't exist
- Provides clear success/failure feedback
- Returns proper exit codes for automation
Requirements:
- Python 3+
- Node.js and npm (for npx)
- markdown-docx npm package (automatically fetched via npx)
位置:
scripts/convert_md_to_docx.py特性:
- 验证输入文件是否存在且为Markdown格式
- 自动生成输出文件名(input.md → input.docx)
- 支持为单个文件自定义输出路径
- 支持批量转换到指定输出目录
- 自动创建不存在的输出目录
- 提供清晰的成功/失败反馈
- 返回合适的退出码以支持自动化
要求:
- Python 3+
- Node.js和npm(用于npx)
- markdown-docx npm包(通过npx自动获取)
Error Handling
错误处理
The script handles common errors:
- Input file not found - Reports missing file path
- Invalid file type - Ensures input is .md or .markdown
- npx not available - Checks for Node.js/npm installation
- Conversion failure - Captures and reports markdown-docx errors
脚本可处理常见错误:
- 输入文件未找到 - 报告缺失的文件路径
- 无效文件类型 - 确保输入文件为.md或.markdown格式
- npx不可用 - 检查Node.js/npm是否已安装
- 转换失败 - 捕获并报告markdown-docx的错误
Tips
提示
- Auto-naming is preferred - The script automatically names output files, reducing friction
- Batch operations - When converting multiple files, the script shows a summary of successes and failures
- Path handling - Both absolute and relative paths work for input and output
- Glob patterns - Shell glob patterns (*.md) can be used for batch operations
- 优先使用自动命名 - 脚本会自动命名输出文件,减少操作步骤
- 批量操作 - 转换多个文件时,脚本会显示成功和失败的汇总信息
- 路径处理 - 输入和输出均支持绝对路径和相对路径
- 通配符模式 - 批量操作可使用Shell通配符模式(*.md)