md-to-office
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMarkdown to Office Skill
Markdown转Office技能
Overview
概述
This skill enables conversion from Markdown to various Office formats using Pandoc - the universal document converter. Convert your Markdown files to professional Word documents, PowerPoint presentations, PDFs, and more while preserving formatting and structure.
本技能借助Pandoc——通用文档转换器,实现Markdown到多种Office格式的转换。将你的Markdown文件转换为专业的Word文档、PowerPoint演示文稿、PDF等格式,同时保留原有的格式和结构。
How to Use
使用方法
- Provide the Markdown content or file
- Specify the target format (docx, pptx, pdf, etc.)
- Optionally provide a reference template for styling
- I'll convert using Pandoc with optimal settings
Example prompts:
- "Convert this README.md to a professional Word document"
- "Turn my markdown notes into a PowerPoint presentation"
- "Generate a PDF from this markdown with custom styling"
- "Create a Word doc from this markdown using company template"
- 提供Markdown内容或文件
- 指定目标格式(docx, pptx, pdf等)
- (可选)提供用于样式设置的参考模板
- 我会使用Pandoc并通过优化配置完成转换
示例提示:
- "将此README.md转换为专业的Word文档"
- "把我的Markdown笔记转成PowerPoint演示文稿"
- "根据此Markdown内容生成带自定义样式的PDF"
- "使用公司模板将此Markdown内容创建为Word文档"
Domain Knowledge
领域知识
Pandoc Fundamentals
Pandoc基础
bash
undefinedbash
undefinedBasic conversion
Basic conversion
pandoc input.md -o output.docx
pandoc input.md -o output.pdf
pandoc input.md -o output.pptx
pandoc input.md -o output.docx
pandoc input.md -o output.pdf
pandoc input.md -o output.pptx
With template
With template
pandoc input.md --reference-doc=template.docx -o output.docx
pandoc input.md --reference-doc=template.docx -o output.docx
Multiple inputs
Multiple inputs
pandoc ch1.md ch2.md ch3.md -o book.docx
undefinedpandoc ch1.md ch2.md ch3.md -o book.docx
undefinedSupported Conversions
支持的转换类型
| From | To | Command |
|---|---|---|
| Markdown | Word | |
| Markdown | | |
| Markdown | PowerPoint | |
| Markdown | HTML | |
| Markdown | LaTeX | |
| Markdown | EPUB | |
| 源格式 | 目标格式 | 命令 |
|---|---|---|
| Markdown | Word | |
| Markdown | | |
| Markdown | PowerPoint | |
| Markdown | HTML | |
| Markdown | LaTeX | |
| Markdown | EPUB | |
Markdown to Word (.docx)
Markdown转Word (.docx)
Basic Conversion
基础转换
bash
pandoc document.md -o document.docxbash
pandoc document.md -o document.docxWith Template (Reference Doc)
使用模板(参考文档)
bash
undefinedbash
undefinedFirst create a template by converting sample
First create a template by converting sample
pandoc sample.md -o reference.docx
pandoc sample.md -o reference.docx
Edit reference.docx styles in Word, then use it
Edit reference.docx styles in Word, then use it
pandoc input.md --reference-doc=reference.docx -o output.docx
undefinedpandoc input.md --reference-doc=reference.docx -o output.docx
undefinedWith Table of Contents
包含目录
bash
pandoc document.md --toc --toc-depth=3 -o document.docxbash
pandoc document.md --toc --toc-depth=3 -o document.docxWith Metadata
包含元数据
bash
pandoc document.md \
--metadata title="My Report" \
--metadata author="John Doe" \
--metadata date="2024-01-15" \
-o document.docxbash
pandoc document.md \
--metadata title="My Report" \
--metadata author="John Doe" \
--metadata date="2024-01-15" \
-o document.docxMarkdown to PDF
Markdown转PDF
Via LaTeX (Best Quality)
通过LaTeX(最佳质量)
bash
undefinedbash
undefinedRequires LaTeX installation
Requires LaTeX installation
pandoc document.md -o document.pdf
pandoc document.md -o document.pdf
With custom settings
With custom settings
pandoc document.md
--pdf-engine=xelatex
-V geometry:margin=1in
-V fontsize=12pt
-o document.pdf
--pdf-engine=xelatex
-V geometry:margin=1in
-V fontsize=12pt
-o document.pdf
undefinedpandoc document.md
--pdf-engine=xelatex
-V geometry:margin=1in
-V fontsize=12pt
-o document.pdf
--pdf-engine=xelatex
-V geometry:margin=1in
-V fontsize=12pt
-o document.pdf
undefinedVia HTML/wkhtmltopdf
通过HTML/wkhtmltopdf
bash
pandoc document.md \
--pdf-engine=wkhtmltopdf \
--css=style.css \
-o document.pdfbash
pandoc document.md \
--pdf-engine=wkhtmltopdf \
--css=style.css \
-o document.pdfPDF Options
PDF选项
bash
pandoc document.md \
-V papersize:a4 \
-V geometry:margin=2cm \
-V fontfamily:libertinus \
-V colorlinks:true \
--toc \
-o document.pdfbash
pandoc document.md \
-V papersize:a4 \
-V geometry:margin=2cm \
-V fontfamily:libertinus \
-V colorlinks:true \
--toc \
-o document.pdfMarkdown to PowerPoint (.pptx)
Markdown转PowerPoint (.pptx)
Basic Conversion
基础转换
bash
pandoc slides.md -o presentation.pptxbash
pandoc slides.md -o presentation.pptxMarkdown Structure for Slides
幻灯片的Markdown结构
markdown
---
title: Presentation Title
author: Author Name
date: January 2024
---markdown
---
title: Presentation Title
author: Author Name
date: January 2024
---Section Header (creates section divider)
Section Header (creates section divider)
Slide Title
Slide Title
- Bullet point 1
- Bullet point 2
- Sub-bullet
- Bullet point 1
- Bullet point 2
- Sub-bullet
Another Slide
Another Slide
Content here
::: notes
Speaker notes go here (not visible in slides)
:::
Content here
::: notes
Speaker notes go here (not visible in slides)
:::
Slide with Image
Slide with Image
{width=80%}
{width=80%}Two Column Slide
Two Column Slide
:::::::::::::: {.columns}
::: {.column width="50%"}
Left column content
:::
::: {.column width="50%"}
Right column content
:::
::::::::::::::
undefined:::::::::::::: {.columns}
::: {.column width="50%"}
Left column content
:::
::: {.column width="50%"}
Right column content
:::
::::::::::::::
undefinedWith Template
使用模板
bash
undefinedbash
undefinedUse corporate PowerPoint template
Use corporate PowerPoint template
pandoc slides.md --reference-doc=template.pptx -o presentation.pptx
undefinedpandoc slides.md --reference-doc=template.pptx -o presentation.pptx
undefinedYAML Frontmatter
YAML前置元数据
Add metadata at the top of your Markdown:
yaml
---
title: "Document Title"
author: "Author Name"
date: "2024-01-15"
abstract: "Brief description"
toc: true
toc-depth: 2
numbersections: true
geometry: margin=1in
fontsize: 11pt
documentclass: report
---在Markdown顶部添加元数据:
yaml
---
title: "Document Title"
author: "Author Name"
date: "2024-01-15"
abstract: "Brief description"
toc: true
toc-depth: 2
numbersections: true
geometry: margin=1in
fontsize: 11pt
documentclass: report
---First Chapter
First Chapter
...
undefined...
undefinedPython Integration
Python集成
python
import subprocess
import os
def md_to_docx(input_path, output_path, template=None):
"""Convert Markdown to Word document."""
cmd = ['pandoc', input_path, '-o', output_path]
if template:
cmd.extend(['--reference-doc', template])
subprocess.run(cmd, check=True)
return output_path
def md_to_pdf(input_path, output_path, **options):
"""Convert Markdown to PDF with options."""
cmd = ['pandoc', input_path, '-o', output_path]
if options.get('toc'):
cmd.append('--toc')
if options.get('margin'):
cmd.extend(['-V', f"geometry:margin={options['margin']}"])
subprocess.run(cmd, check=True)
return output_path
def md_to_pptx(input_path, output_path, template=None):
"""Convert Markdown to PowerPoint."""
cmd = ['pandoc', input_path, '-o', output_path]
if template:
cmd.extend(['--reference-doc', template])
subprocess.run(cmd, check=True)
return output_pathpython
import subprocess
import os
def md_to_docx(input_path, output_path, template=None):
"""Convert Markdown to Word document."""
cmd = ['pandoc', input_path, '-o', output_path]
if template:
cmd.extend(['--reference-doc', template])
subprocess.run(cmd, check=True)
return output_path
def md_to_pdf(input_path, output_path, **options):
"""Convert Markdown to PDF with options."""
cmd = ['pandoc', input_path, '-o', output_path]
if options.get('toc'):
cmd.append('--toc')
if options.get('margin'):
cmd.extend(['-V', f"geometry:margin={options['margin']}"])
subprocess.run(cmd, check=True)
return output_path
def md_to_pptx(input_path, output_path, template=None):
"""Convert Markdown to PowerPoint."""
cmd = ['pandoc', input_path, '-o', output_path]
if template:
cmd.extend(['--reference-doc', template])
subprocess.run(cmd, check=True)
return output_pathpypandoc (Python Wrapper)
pypandoc(Python包装器)
python
import pypandocpython
import pypandocSimple conversion
Simple conversion
output = pypandoc.convert_file('input.md', 'docx', outputfile='output.docx')
output = pypandoc.convert_file('input.md', 'docx', outputfile='output.docx')
With options
With options
output = pypandoc.convert_file(
'input.md',
'docx',
outputfile='output.docx',
extra_args=['--toc', '--reference-doc=template.docx']
)
output = pypandoc.convert_file(
'input.md',
'docx',
outputfile='output.docx',
extra_args=['--toc', '--reference-doc=template.docx']
)
From string
From string
md_content = "# Hello\n\nThis is markdown."
output = pypandoc.convert_text(md_content, 'docx', format='md', outputfile='output.docx')
undefinedmd_content = "# Hello\n\nThis is markdown."
output = pypandoc.convert_text(md_content, 'docx', format='md', outputfile='output.docx')
undefinedBest Practices
最佳实践
- Use Templates: Create a reference document for consistent branding
- Structure Headers: Use consistent heading levels (## for slides, # for sections)
- Test Incrementally: Convert small sections first to verify formatting
- Include Metadata: Use YAML frontmatter for document properties
- Handle Images: Use relative paths and specify dimensions
- 使用模板:创建参考文档以保持品牌一致性
- 结构化标题:使用统一的标题层级(幻灯片用##,章节用#)
- 增量测试:先转换小部分内容以验证格式
- 包含元数据:使用YAML前置元数据设置文档属性
- 处理图片:使用相对路径并指定尺寸
Common Patterns
常见模式
Batch Conversion
批量转换
python
import subprocess
from pathlib import Path
def batch_convert(input_dir, output_format, output_dir=None):
"""Convert all markdown files in a directory."""
input_path = Path(input_dir)
output_path = Path(output_dir) if output_dir else input_path
for md_file in input_path.glob('*.md'):
output_file = output_path / md_file.with_suffix(f'.{output_format}').name
subprocess.run([
'pandoc', str(md_file), '-o', str(output_file)
], check=True)
print(f"Converted: {md_file.name} -> {output_file.name}")
batch_convert('./docs', 'docx', './output')python
import subprocess
from pathlib import Path
def batch_convert(input_dir, output_format, output_dir=None):
"""Convert all markdown files in a directory."""
input_path = Path(input_dir)
output_path = Path(output_dir) if output_dir else input_path
for md_file in input_path.glob('*.md'):
output_file = output_path / md_file.with_suffix(f'.{output_format}').name
subprocess.run([
'pandoc', str(md_file), '-o', str(output_file)
], check=True)
print(f"Converted: {md_file.name} -> {output_file.name}")
batch_convert('./docs', 'docx', './output')Report Generator
报告生成器
python
def generate_report(title, sections, output_path, template=None):
"""Generate Word report from structured data."""
# Build markdown
md_content = f"""---
title: "{title}"
date: "{datetime.now().strftime('%B %d, %Y')}"
---
"""
for section_title, content in sections.items():
md_content += f"# {section_title}\n\n{content}\n\n"
# Write temp file
with open('temp_report.md', 'w') as f:
f.write(md_content)
# Convert
cmd = ['pandoc', 'temp_report.md', '-o', output_path, '--toc']
if template:
cmd.extend(['--reference-doc', template])
subprocess.run(cmd, check=True)
os.remove('temp_report.md')python
def generate_report(title, sections, output_path, template=None):
"""Generate Word report from structured data."""
# Build markdown
md_content = f"""---
title: "{title}"
date: "{datetime.now().strftime('%B %d, %Y')}"
---
"""
for section_title, content in sections.items():
md_content += f"# {section_title}\n\n{content}\n\n"
# Write temp file
with open('temp_report.md', 'w') as f:
f.write(md_content)
# Convert
cmd = ['pandoc', 'temp_report.md', '-o', output_path, '--toc']
if template:
cmd.extend(['--reference-doc', template])
subprocess.run(cmd, check=True)
os.remove('temp_report.md')Examples
示例
Example 1: Technical Documentation
示例1:技术文档转换
python
import subprocesspython
import subprocessCreate comprehensive markdown
Create comprehensive markdown
doc = """--- title: "API Documentation" author: "Dev Team" date: "2024-01-15" toc: true toc-depth: 2
doc = """--- title: "API Documentation" author: "Dev Team" date: "2024-01-15" toc: true toc-depth: 2
Introduction
Introduction
This document describes the REST API for our service.
This document describes the REST API for our service.
Authentication
Authentication
All API requests require an API key in the header:
Authorization: Bearer YOUR_API_KEYAll API requests require an API key in the header:
Authorization: Bearer YOUR_API_KEYEndpoints
Endpoints
GET /users
GET /users
Retrieve all users.
Response:
| Field | Type | Description |
|---|---|---|
| id | integer | User ID |
| name | string | Full name |
| string | Email address |
Retrieve all users.
Response:
| Field | Type | Description |
|---|---|---|
| id | integer | User ID |
| name | string | Full name |
| string | Email address |
POST /users
POST /users
Create a new user.
Request Body:
json
{
"name": "John Doe",
"email": "john@example.com"
}Create a new user.
Request Body:
json
{
"name": "John Doe",
"email": "john@example.com"
}Error Codes
Error Codes
| Code | Meaning |
|---|---|
| 400 | Bad Request |
| 401 | Unauthorized |
| 404 | Not Found |
| 500 | Server Error |
| """ |
| Code | Meaning |
|---|---|
| 400 | Bad Request |
| 401 | Unauthorized |
| 404 | Not Found |
| 500 | Server Error |
| """ |
Save markdown
Save markdown
with open('api_docs.md', 'w') as f:
f.write(doc)
with open('api_docs.md', 'w') as f:
f.write(doc)
Convert to Word
Convert to Word
subprocess.run([
'pandoc', 'api_docs.md',
'-o', 'api_documentation.docx',
'--toc',
'--reference-doc', 'company_template.docx'
], check=True)
subprocess.run([
'pandoc', 'api_docs.md',
'-o', 'api_documentation.docx',
'--toc',
'--reference-doc', 'company_template.docx'
], check=True)
Convert to PDF
Convert to PDF
subprocess.run([
'pandoc', 'api_docs.md',
'-o', 'api_documentation.pdf',
'--toc',
'-V', 'geometry:margin=1in',
'-V', 'fontsize=11pt'
], check=True)
undefinedsubprocess.run([
'pandoc', 'api_docs.md',
'-o', 'api_documentation.pdf',
'--toc',
'-V', 'geometry:margin=1in',
'-V', 'fontsize=11pt'
], check=True)
undefinedExample 2: Presentation from Markdown
示例2:从Markdown生成演示文稿
python
slides_md = """---
title: "Q4 Business Review"
author: "Sales Team"
date: "January 2024"
---python
slides_md = """---
title: "Q4 Business Review"
author: "Sales Team"
date: "January 2024"
---Overview
Overview
Agenda
Agenda
- Q4 Performance Summary
- Regional Highlights
- 2024 Outlook
- Q&A
- Q4 Performance Summary
- Regional Highlights
- 2024 Outlook
- Q&A
Q4 Performance
Q4 Performance
Key Metrics
Key Metrics
- Revenue: $12.5M (+15% YoY)
- New Customers: 250
- Retention Rate: 94%
- Revenue: $12.5M (+15% YoY)
- New Customers: 250
- Retention Rate: 94%
Regional Performance
Regional Performance
:::::::::::::: {.columns}
::: {.column width="50%"}
North America
- Revenue: $6.2M
- Growth: +18% :::
::: {.column width="50%"}
Europe
- Revenue: $4.1M
- Growth: +12% ::: ::::::::::::::
:::::::::::::: {.columns}
::: {.column width="50%"}
North America
- Revenue: $6.2M
- Growth: +18% :::
::: {.column width="50%"}
Europe
- Revenue: $4.1M
- Growth: +12% ::: ::::::::::::::
2024 Outlook
2024 Outlook
Strategic Priorities
Strategic Priorities
- Expand APAC presence
- Launch new product line
- Improve customer onboarding
- Expand APAC presence
- Launch new product line
- Improve customer onboarding
Revenue Targets
Revenue Targets
| Quarter | Target |
|---|---|
| Q1 | $13M |
| Q2 | $14M |
| Q3 | $15M |
| Q4 | $16M |
| Quarter | Target |
|---|---|
| Q1 | $13M |
| Q2 | $14M |
| Q3 | $15M |
| Q4 | $16M |
Thank You
Thank You
Questions?
Questions?
Contact: sales@company.com
"""
with open('presentation.md', 'w') as f:
f.write(slides_md)
subprocess.run([
'pandoc', 'presentation.md',
'-o', 'q4_review.pptx',
'--reference-doc', 'company_slides.pptx'
], check=True)
undefinedContact: sales@company.com
"""
with open('presentation.md', 'w') as f:
f.write(slides_md)
subprocess.run([
'pandoc', 'presentation.md',
'-o', 'q4_review.pptx',
'--reference-doc', 'company_slides.pptx'
], check=True)
undefinedLimitations
局限性
- Complex Word formatting may not convert perfectly
- PDF conversion requires LaTeX or wkhtmltopdf
- PowerPoint animations not supported
- Some advanced tables may need manual adjustment
- Image positioning can be tricky
- 复杂的Word格式可能无法完美转换
- PDF转换需要安装LaTeX或wkhtmltopdf
- 不支持PowerPoint动画效果
- 部分复杂表格可能需要手动调整
- 图片定位可能存在难度
Installation
安装方法
bash
undefinedbash
undefinedmacOS
macOS
brew install pandoc
brew install pandoc
Ubuntu/Debian
Ubuntu/Debian
sudo apt-get install pandoc
sudo apt-get install pandoc
Windows
Windows
choco install pandoc
choco install pandoc
Python wrapper
Python wrapper
pip install pypandoc
undefinedpip install pypandoc
undefined