md-to-office by claude-office-skills/skills
npx skills add https://github.com/claude-office-skills/skills --skill md-to-office此技能利用 Pandoc——通用文档转换器,实现从 Markdown 到多种 Office 格式的转换。将您的 Markdown 文件转换为专业的 Word 文档、PowerPoint 演示文稿、PDF 等,同时保留格式和结构。
示例提示:
# 基本转换
pandoc input.md -o output.docx
pandoc input.md -o output.pdf
pandoc input.md -o output.pptx
# 使用模板
pandoc input.md --reference-doc=template.docx -o output.docx
# 多个输入文件
pandoc ch1.md ch2.md ch3.md -o book.docx
| 源格式 | 目标格式 | 命令 |
|---|---|---|
| Markdown | Word |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
pandoc in.md -o out.docx |
| Markdown | pandoc in.md -o out.pdf |
| Markdown | PowerPoint | pandoc in.md -o out.pptx |
| Markdown | HTML | pandoc in.md -o out.html |
| Markdown | LaTeX | pandoc in.md -o out.tex |
| Markdown | EPUB | pandoc in.md -o out.epub |
pandoc document.md -o document.docx
# 首先通过转换示例创建模板
pandoc sample.md -o reference.docx
# 在 Word 中编辑 reference.docx 的样式,然后使用它
pandoc input.md --reference-doc=reference.docx -o output.docx
pandoc document.md --toc --toc-depth=3 -o document.docx
pandoc document.md \
--metadata title="My Report" \
--metadata author="John Doe" \
--metadata date="2024-01-15" \
-o document.docx
# 需要安装 LaTeX
pandoc document.md -o document.pdf
# 使用自定义设置
pandoc document.md \
--pdf-engine=xelatex \
-V geometry:margin=1in \
-V fontsize=12pt \
-o document.pdf
pandoc document.md \
--pdf-engine=wkhtmltopdf \
--css=style.css \
-o document.pdf
pandoc document.md \
-V papersize:a4 \
-V geometry:margin=2cm \
-V fontfamily:libertinus \
-V colorlinks:true \
--toc \
-o document.pdf
pandoc slides.md -o presentation.pptx
---
title: Presentation Title
author: Author Name
date: January 2024
---
# Section Header (creates section divider)
## Slide Title
- Bullet point 1
- Bullet point 2
- Sub-bullet
## Another Slide
Content here
::: notes
Speaker notes go here (not visible in slides)
:::
## Slide with Image
{width=80%}
## Two Column Slide
:::::::::::::: {.columns}
::: {.column width="50%"}
Left column content
:::
::: {.column width="50%"}
Right column content
:::
::::::::::::::
# 使用公司 PowerPoint 模板
pandoc slides.md --reference-doc=template.pptx -o presentation.pptx
在 Markdown 文件顶部添加元数据:
---
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
...
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_path
import pypandoc
# 简单转换
output = pypandoc.convert_file('input.md', 'docx', outputfile='output.docx')
# 带选项
output = pypandoc.convert_file(
'input.md',
'docx',
outputfile='output.docx',
extra_args=['--toc', '--reference-doc=template.docx']
)
# 从字符串转换
md_content = "# Hello\n\nThis is markdown."
output = pypandoc.convert_text(md_content, 'docx', format='md', outputfile='output.docx')
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')
def generate_report(title, sections, output_path, template=None):
"""Generate Word report from structured data."""
# 构建 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"
# 写入临时文件
with open('temp_report.md', 'w') as f:
f.write(md_content)
# 转换
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')
import subprocess
# 创建完整的 markdown 文档
doc = """---
title: "API Documentation"
author: "Dev Team"
date: "2024-01-15"
toc: true
toc-depth: 2
---
# Introduction
This document describes the REST API for our service.
## Authentication
All API requests require an API key in the header:
Authorization: Bearer YOUR_API_KEY
## Endpoints
### GET /users
Retrieve all users.
**Response:**
| Field | Type | Description |
|-------|------|-------------|
| id | integer | User ID |
| name | string | Full name |
| email | string | Email address |
### POST /users
Create a new user.
**Request Body:**
```json
{
"name": "John Doe",
"email": "john@example.com"
}
| Code | Meaning |
|---|---|
| 400 | Bad Request |
| 401 | Unauthorized |
| 404 | Not Found |
| 500 | Server Error |
| """ |
with open('api_docs.md', 'w') as f: f.write(doc)
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.pdf', '--toc', '-V', 'geometry:margin=1in', '-V', 'fontsize=11pt' ], check=True)
### 示例 2:从 Markdown 生成演示文稿
```python
slides_md = """---
title: "Q4 Business Review"
author: "Sales Team"
date: "January 2024"
---
# Overview
## Agenda
- Q4 Performance Summary
- Regional Highlights
- 2024 Outlook
- Q&A
# Q4 Performance
## Key Metrics
- Revenue: $12.5M (+15% YoY)
- New Customers: 250
- Retention Rate: 94%
## Regional Performance
:::::::::::::: {.columns}
::: {.column width="50%"}
**North America**
- Revenue: $6.2M
- Growth: +18%
:::
::: {.column width="50%"}
**Europe**
- Revenue: $4.1M
- Growth: +12%
:::
::::::::::::::
# 2024 Outlook
## Strategic Priorities
1. Expand APAC presence
2. Launch new product line
3. Improve customer onboarding
## Revenue Targets
| Quarter | Target |
|---------|--------|
| Q1 | $13M |
| Q2 | $14M |
| Q3 | $15M |
| Q4 | $16M |
# Thank You
## 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)
# macOS
brew install pandoc
# Ubuntu/Debian
sudo apt-get install pandoc
# Windows
choco install pandoc
# Python 封装库
pip install pypandoc
每周安装次数
66
仓库
GitHub 星标数
5
首次出现
2 天前
安全审计
安装于
claude-code49
gemini-cli28
amp28
cline28
github-copilot28
codex28
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.
Example prompts:
# Basic conversion
pandoc input.md -o output.docx
pandoc input.md -o output.pdf
pandoc input.md -o output.pptx
# With template
pandoc input.md --reference-doc=template.docx -o output.docx
# Multiple inputs
pandoc ch1.md ch2.md ch3.md -o book.docx
| From | To | Command |
|---|---|---|
| Markdown | Word | pandoc in.md -o out.docx |
| Markdown | pandoc in.md -o out.pdf | |
| Markdown | PowerPoint | pandoc in.md -o out.pptx |
| Markdown | HTML | pandoc in.md -o out.html |
| Markdown | LaTeX | pandoc in.md -o out.tex |
| Markdown | EPUB | pandoc in.md -o out.epub |
pandoc document.md -o document.docx
# First create a template by converting sample
pandoc sample.md -o reference.docx
# Edit reference.docx styles in Word, then use it
pandoc input.md --reference-doc=reference.docx -o output.docx
pandoc document.md --toc --toc-depth=3 -o document.docx
pandoc document.md \
--metadata title="My Report" \
--metadata author="John Doe" \
--metadata date="2024-01-15" \
-o document.docx
# Requires LaTeX installation
pandoc document.md -o document.pdf
# With custom settings
pandoc document.md \
--pdf-engine=xelatex \
-V geometry:margin=1in \
-V fontsize=12pt \
-o document.pdf
pandoc document.md \
--pdf-engine=wkhtmltopdf \
--css=style.css \
-o document.pdf
pandoc document.md \
-V papersize:a4 \
-V geometry:margin=2cm \
-V fontfamily:libertinus \
-V colorlinks:true \
--toc \
-o document.pdf
pandoc slides.md -o presentation.pptx
---
title: Presentation Title
author: Author Name
date: January 2024
---
# Section Header (creates section divider)
## Slide Title
- Bullet point 1
- Bullet point 2
- Sub-bullet
## Another Slide
Content here
::: notes
Speaker notes go here (not visible in slides)
:::
## Slide with Image
{width=80%}
## Two Column Slide
:::::::::::::: {.columns}
::: {.column width="50%"}
Left column content
:::
::: {.column width="50%"}
Right column content
:::
::::::::::::::
# Use corporate PowerPoint template
pandoc slides.md --reference-doc=template.pptx -o presentation.pptx
Add metadata at the top of your Markdown:
---
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
...
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_path
import pypandoc
# Simple conversion
output = pypandoc.convert_file('input.md', 'docx', outputfile='output.docx')
# With options
output = pypandoc.convert_file(
'input.md',
'docx',
outputfile='output.docx',
extra_args=['--toc', '--reference-doc=template.docx']
)
# From string
md_content = "# Hello\n\nThis is markdown."
output = pypandoc.convert_text(md_content, 'docx', format='md', outputfile='output.docx')
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')
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')
import subprocess
# Create comprehensive markdown
doc = """---
title: "API Documentation"
author: "Dev Team"
date: "2024-01-15"
toc: true
toc-depth: 2
---
# Introduction
This document describes the REST API for our service.
## Authentication
All API requests require an API key in the header:
Authorization: Bearer YOUR_API_KEY
## Endpoints
### GET /users
Retrieve all users.
**Response:**
| Field | Type | Description |
|-------|------|-------------|
| id | integer | User ID |
| name | string | Full name |
| email | string | Email address |
### POST /users
Create a new user.
**Request Body:**
```json
{
"name": "John Doe",
"email": "john@example.com"
}
| Code | Meaning |
|---|---|
| 400 | Bad Request |
| 401 | Unauthorized |
| 404 | Not Found |
| 500 | Server Error |
| """ |
with open('api_docs.md', 'w') as f: f.write(doc)
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.pdf', '--toc', '-V', 'geometry:margin=1in', '-V', 'fontsize=11pt' ], check=True)
### Example 2: Presentation from Markdown
```python
slides_md = """---
title: "Q4 Business Review"
author: "Sales Team"
date: "January 2024"
---
# Overview
## Agenda
- Q4 Performance Summary
- Regional Highlights
- 2024 Outlook
- Q&A
# Q4 Performance
## Key Metrics
- Revenue: $12.5M (+15% YoY)
- New Customers: 250
- Retention Rate: 94%
## Regional Performance
:::::::::::::: {.columns}
::: {.column width="50%"}
**North America**
- Revenue: $6.2M
- Growth: +18%
:::
::: {.column width="50%"}
**Europe**
- Revenue: $4.1M
- Growth: +12%
:::
::::::::::::::
# 2024 Outlook
## Strategic Priorities
1. Expand APAC presence
2. Launch new product line
3. Improve customer onboarding
## Revenue Targets
| Quarter | Target |
|---------|--------|
| Q1 | $13M |
| Q2 | $14M |
| Q3 | $15M |
| Q4 | $16M |
# Thank You
## 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)
# macOS
brew install pandoc
# Ubuntu/Debian
sudo apt-get install pandoc
# Windows
choco install pandoc
# Python wrapper
pip install pypandoc
Weekly Installs
66
Repository
GitHub Stars
5
First Seen
2 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code49
gemini-cli28
amp28
cline28
github-copilot28
codex28
xdrop 文件传输脚本:Bun 环境下安全上传下载工具,支持加密分享
20,700 周安装
Firebase应用托管基础教程:部署Next.js、Angular全栈Web应用
297 周安装
智能代码探索工具smart-explore:AST解析结构化代码搜索与导航
297 周安装
GrepAI Ollama 本地安装配置教程 - 私有化代码搜索嵌入模型设置指南
297 周安装
YouTube 全功能工具包:转录、搜索、频道分析 API | TranscriptAPI.com 集成
297 周安装
Firebase AI Logic 入门指南:为移动和Web应用集成Gemini生成式AI
297 周安装
UX设计原则与可用性启发式指南 | 用户研究、设计思维、尼尔森十大原则
297 周安装