pandoc by plinde/claude-plugins
npx skills add https://github.com/plinde/claude-plugins --skill pandoc使用 pandoc(通用文档转换器)在不同格式之间转换文档。
# 检查是否已安装 pandoc
pandoc --version
# 如果需要,通过 Homebrew 安装
brew install pandoc
# 基本转换
pandoc input.md -o output.docx
# 带目录
pandoc input.md --toc -o output.docx
# 使用自定义参考文档(用于样式设置)
pandoc input.md --reference-doc=template.docx -o output.docx
# 独立文档并包含元数据
pandoc input.md -s --metadata title="文档标题" -o output.docx
# 需要 LaTeX - 安装以下之一:
# brew install --cask basictex # 较小(约 100MB)
# brew install --cask mactex-no-gui # 完整版(约 4GB)
# 安装后执行:eval "$(/usr/libexec/path_helper)" 或打开新终端
# 基本转换(使用 pdflatex)
pandoc input.md -o output.pdf
# 带目录和自定义边距
pandoc input.md -s --toc --toc-depth=2 -V geometry:margin=1in -o output.pdf
# 使用 xelatex(更好的 Unicode 支持 - 方框绘图、箭头等)
export PATH="/Library/TeX/texbin:$PATH"
pandoc input.md --pdf-engine=xelatex -V geometry:margin=1in -o output.pdf
PDF 引擎选择:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 引擎 | 使用场景 |
|---|---|
pdflatex | 默认,仅限 ASCII 内容 |
xelatex | Unicode 字符(箭头、方框绘图、表情符号) |
lualatex | 复杂排版,OpenType 字体 |
重要提示: 为了正确处理换行符和列表,请始终使用 -f gfm(GitHub 风格的 Markdown)。标准 markdown 会将连续行合并为段落。
# 推荐:GitHub 风格的 Markdown 并包含完整样式
pandoc -f gfm -s -H <(cat << 'STYLE'
<style>
body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;max-width:800px;margin:0 auto;padding:2em;line-height:1.6}
h1{border-bottom:2px solid #333;padding-bottom:0.3em}
h2{border-bottom:1px solid #ccc;padding-bottom:0.2em;margin-top:1.5em}
h3{margin-top:1.2em}
ul,ol{margin:0.5em 0 0.5em 1.5em;padding-left:1em}
ul{list-style-type:disc}ol{list-style-type:decimal}
li{margin:0.3em 0}ul ul,ol ul{list-style-type:circle;margin:0.2em 0 0.2em 1em}
table{border-collapse:collapse;width:100%;margin:1em 0}
th,td{border:1px solid #ddd;padding:8px;text-align:left}
th{background-color:#f5f5f5}
code{background-color:#f4f4f4;padding:2px 6px;border-radius:3px}
pre{background-color:#f4f4f4;padding:1em;overflow-x:auto;border-radius:5px}
blockquote{border-left:4px solid #ddd;margin:1em 0;padding-left:1em;color:#666}
</style>
STYLE
) input.md -o output.html
# 快速版本(最小样式)
pandoc -f gfm -s input.md -o output.html
# 带硬换行符(换行符变为 <br>)
pandoc -f markdown+hard_line_breaks -s input.md -o output.html
# 自包含(嵌入图像/CSS)
pandoc -f gfm -s --embed-resources --standalone input.md -o output.html
格式选项:
| 选项 | 使用场景 |
|---|---|
-f gfm | 默认选择 - 正确处理列表、换行符、表格 |
-f markdown+hard_line_breaks | 强制所有换行符变为 <br> |
-f commonmark | 严格遵循 CommonMark 规范 |
当 LaTeX 不可用时,创建带样式的 HTML 并从浏览器打印到 PDF:
# 创建内联 CSS 文件
cat > /tmp/print-style.css << 'EOF'
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
max-width: 800px; margin: 0 auto; padding: 2em; line-height: 1.6; }
h1 { border-bottom: 2px solid #333; padding-bottom: 0.3em; }
h2 { border-bottom: 1px solid #ccc; padding-bottom: 0.2em; margin-top: 1.5em; }
h3 { margin-top: 1.2em; }
/* 列表 - 正确渲染的关键 */
ul, ol { margin: 0.5em 0 0.5em 1.5em; padding-left: 1em; }
ul { list-style-type: disc; }
ol { list-style-type: decimal; }
li { margin: 0.3em 0; }
ul ul, ol ul { list-style-type: circle; margin: 0.2em 0 0.2em 1em; }
ul ol, ol ol { margin: 0.2em 0 0.2em 1em; }
ul ul ul, ol ul ul { list-style-type: square; }
/* 表格 */
table { border-collapse: collapse; width: 100%; margin: 1em 0; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f5f5f5; }
/* 代码 */
code { background-color: #f4f4f4; padding: 2px 6px; border-radius: 3px; }
pre { background-color: #f4f4f4; padding: 1em; overflow-x: auto; border-radius: 5px; }
/* 其他 */
blockquote { border-left: 4px solid #ddd; margin: 1em 0; padding-left: 1em; color: #666; }
@media print { body { max-width: none; } }
EOF
# 使用嵌入样式进行转换(始终使用 -f gfm)
pandoc -f gfm input.md -s --toc --toc-depth=2 -c /tmp/print-style.css --embed-resources --standalone -o output.html
# 打开并打印到 PDF(Cmd+P > 另存为 PDF)
open output.html
# 从 docx 提取 markdown
pandoc input.docx -o output.md
# 使用 ATX 风格标题
pandoc input.docx --atx-headers -o output.md
| 选项 | 描述 |
|---|---|
-s / --standalone | 生成包含页眉/页脚的独立文档 |
--toc | 生成目录 |
--toc-depth=N | 目录深度(默认:3) |
-V key=value | 设置模板变量 |
--metadata key=value | 设置元数据字段 |
--reference-doc=FILE | 使用 FILE 进行样式设置(docx/odt) |
--template=FILE | 使用自定义模板 |
--highlight-style=STYLE | 语法高亮(pygments、tango 等) |
--number-sections | 为章节标题编号 |
-f FORMAT | 输入格式(如果未自动检测) |
-t FORMAT | 输出格式(如果未自动检测) |
| 格式 | 标识符 |
|---|---|
| Markdown | markdown、gfm(GitHub)、commonmark |
| Word | docx |
pdf | |
| HTML | html、html5 |
| LaTeX | latex |
| RST | rst |
| EPUB | epub |
| ODT | odt |
| RTF | rtf |
要将 markdown 导入 Google 文档并保留格式:
# 1. 转换为 docx
pandoc document.md -o document.docx
# 2. 上传到 Google Drive
# 3. 右键单击 > 使用...打开 > Google 文档
Google 文档能很好地导入 .docx 文件并保留:
对于包含表格和复杂格式的 PSI 文档:
# 将 PSI markdown 转换为 Word
pandoc PSI-document.md \
--standalone \
--toc \
--toc-depth=2 \
-o PSI-document.docx
# 打开进行审阅
open PSI-document.docx
如果项目符号、编号列表或连续行合并为一个段落:
原因: 标准 markdown 将连续行视为一个段落。列表前需要空行。
修复: 使用 GitHub 风格的 Markdown(-f gfm):
# 始终使用 -f gfm 以获得可靠的格式
pandoc -f gfm -s input.md -o output.html
# 对于换行符应变为 <br> 标签的文档
pandoc -f markdown+hard_line_breaks -s input.md -o output.html
为什么会发生这种情况:
Line 1\nLine 2 → <p>Line 1 Line 2</p>(合并)+hard_line_breaks:Line 1\nLine 2 → Line 1<br>Line 2(保留)Pandoc 需要正确的 markdown 表格语法:
| 标题 1 | 标题 2 |
|----------|----------|
| 单元格 1 | 单元格 2 |
使用带语言标识符的围栏代码块:
```python
def example():
pass
### PDF 生成失败
**"找不到 pdflatex"** - 安装 LaTeX:
```bash
# 较小选项(约 100MB)
brew install --cask basictex
# 完整选项(约 4GB)
brew install --cask mactex-no-gui
# 安装后,更新 PATH
eval "$(/usr/libexec/path_helper)"
# 或打开新终端
Unicode 字符错误(方框绘图、箭头、表情符号):
# 使用 xelatex 替代 pdflatex
export PATH="/Library/TeX/texbin:$PATH"
pandoc input.md --pdf-engine=xelatex -o output.pdf
没有可用的 LaTeX - 使用 HTML 打印到 PDF 工作流程:
pandoc input.md -s --toc -o output.html
open output.html
# 然后 Cmd+P > 另存为 PDF
# 验证 pandoc 安装
pandoc --version | head -1
# 测试基本转换
echo "# 测试\n\n你好 **世界**" | pandoc -f markdown -t html
每周安装次数
116
代码仓库
GitHub 星标数
6
首次出现
2026年2月4日
安全审计
安装于
gemini-cli113
codex113
opencode112
cursor111
github-copilot111
kimi-cli110
Convert documents between formats using pandoc, the universal document converter.
# Check if pandoc is installed
pandoc --version
# Install via Homebrew if needed
brew install pandoc
# Basic conversion
pandoc input.md -o output.docx
# With table of contents
pandoc input.md --toc -o output.docx
# With custom reference doc (for styling)
pandoc input.md --reference-doc=template.docx -o output.docx
# Standalone with metadata
pandoc input.md -s --metadata title="Document Title" -o output.docx
# Requires LaTeX - install one of:
# brew install --cask basictex # Smaller (~100MB)
# brew install --cask mactex-no-gui # Full (~4GB)
# After install: eval "$(/usr/libexec/path_helper)" or new terminal
# Basic conversion (uses pdflatex)
pandoc input.md -o output.pdf
# With table of contents and custom margins
pandoc input.md -s --toc --toc-depth=2 -V geometry:margin=1in -o output.pdf
# Using xelatex (better Unicode support - box drawings, arrows, etc.)
export PATH="/Library/TeX/texbin:$PATH"
pandoc input.md --pdf-engine=xelatex -V geometry:margin=1in -o output.pdf
PDF Engine Selection:
| Engine | Use When |
|---|---|
pdflatex | Default, ASCII content only |
xelatex | Unicode characters (arrows, box-drawing, emojis) |
lualatex | Complex typography, OpenType fonts |
Critical: Always use -f gfm (GitHub Flavored Markdown) for proper line break and list handling. Standard markdown collapses consecutive lines into paragraphs.
# RECOMMENDED: GitHub Flavored Markdown with full styling
pandoc -f gfm -s -H <(cat << 'STYLE'
<style>
body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;max-width:800px;margin:0 auto;padding:2em;line-height:1.6}
h1{border-bottom:2px solid #333;padding-bottom:0.3em}
h2{border-bottom:1px solid #ccc;padding-bottom:0.2em;margin-top:1.5em}
h3{margin-top:1.2em}
ul,ol{margin:0.5em 0 0.5em 1.5em;padding-left:1em}
ul{list-style-type:disc}ol{list-style-type:decimal}
li{margin:0.3em 0}ul ul,ol ul{list-style-type:circle;margin:0.2em 0 0.2em 1em}
table{border-collapse:collapse;width:100%;margin:1em 0}
th,td{border:1px solid #ddd;padding:8px;text-align:left}
th{background-color:#f5f5f5}
code{background-color:#f4f4f4;padding:2px 6px;border-radius:3px}
pre{background-color:#f4f4f4;padding:1em;overflow-x:auto;border-radius:5px}
blockquote{border-left:4px solid #ddd;margin:1em 0;padding-left:1em;color:#666}
</style>
STYLE
) input.md -o output.html
# Quick version (minimal styling)
pandoc -f gfm -s input.md -o output.html
# With hard line breaks (newlines become <br>)
pandoc -f markdown+hard_line_breaks -s input.md -o output.html
# Self-contained (embeds images/CSS)
pandoc -f gfm -s --embed-resources --standalone input.md -o output.html
Format Options:
| Option | Use When |
|---|---|
-f gfm | Default choice - handles lists, line breaks, tables correctly |
-f markdown+hard_line_breaks | Force all newlines to become <br> |
-f commonmark | Strict CommonMark compliance |
When LaTeX isn't available, create styled HTML and print to PDF from browser:
# Create inline CSS file
cat > /tmp/print-style.css << 'EOF'
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
max-width: 800px; margin: 0 auto; padding: 2em; line-height: 1.6; }
h1 { border-bottom: 2px solid #333; padding-bottom: 0.3em; }
h2 { border-bottom: 1px solid #ccc; padding-bottom: 0.2em; margin-top: 1.5em; }
h3 { margin-top: 1.2em; }
/* Lists - critical for proper rendering */
ul, ol { margin: 0.5em 0 0.5em 1.5em; padding-left: 1em; }
ul { list-style-type: disc; }
ol { list-style-type: decimal; }
li { margin: 0.3em 0; }
ul ul, ol ul { list-style-type: circle; margin: 0.2em 0 0.2em 1em; }
ul ol, ol ol { margin: 0.2em 0 0.2em 1em; }
ul ul ul, ol ul ul { list-style-type: square; }
/* Tables */
table { border-collapse: collapse; width: 100%; margin: 1em 0; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f5f5f5; }
/* Code */
code { background-color: #f4f4f4; padding: 2px 6px; border-radius: 3px; }
pre { background-color: #f4f4f4; padding: 1em; overflow-x: auto; border-radius: 5px; }
/* Other */
blockquote { border-left: 4px solid #ddd; margin: 1em 0; padding-left: 1em; color: #666; }
@media print { body { max-width: none; } }
EOF
# Convert with embedded styles (ALWAYS use -f gfm)
pandoc -f gfm input.md -s --toc --toc-depth=2 -c /tmp/print-style.css --embed-resources --standalone -o output.html
# Open and print to PDF (Cmd+P > Save as PDF)
open output.html
# Extract markdown from docx
pandoc input.docx -o output.md
# With ATX-style headers
pandoc input.docx --atx-headers -o output.md
| Option | Description |
|---|---|
-s / --standalone | Produce standalone document with header/footer |
--toc | Generate table of contents |
--toc-depth=N | TOC depth (default: 3) |
-V key=value | Set template variable |
--metadata key=value | Set metadata field |
--reference-doc=FILE |
| Format | Identifier |
|---|---|
| Markdown | markdown, gfm (GitHub), commonmark |
| Word | docx |
pdf | |
| HTML | html, html5 |
| LaTeX | latex |
To get markdown into Google Docs with formatting preserved:
# 1. Convert to docx
pandoc document.md -o document.docx
# 2. Upload to Google Drive
# 3. Right-click > Open with > Google Docs
Google Docs imports .docx files well and preserves:
For PSI documents with tables and complex formatting:
# Convert PSI markdown to Word
pandoc PSI-document.md \
--standalone \
--toc \
--toc-depth=2 \
-o PSI-document.docx
# Open for review
open PSI-document.docx
If bullet points, numbered lists, or consecutive lines merge into one paragraph:
Cause: Standard markdown treats consecutive lines as one paragraph. Lists need blank lines before them.
Fix: Use GitHub Flavored Markdown (-f gfm):
# Always use -f gfm for reliable formatting
pandoc -f gfm -s input.md -o output.html
# For documents where newlines should be <br> tags
pandoc -f markdown+hard_line_breaks -s input.md -o output.html
Why this happens:
Line 1\nLine 2 → <p>Line 1 Line 2</p> (merged)+hard_line_breaks: Line 1\nLine 2 → Line 1<br>Line 2 (preserved)Pandoc requires proper markdown table syntax:
| Header 1 | Header 2 |
|----------|----------|
| Cell 1 | Cell 2 |
Use fenced code blocks with language identifier:
```python
def example():
pass
### PDF Generation Fails
**"pdflatex not found"** - Install LaTeX:
```bash
# Smaller option (~100MB)
brew install --cask basictex
# Full option (~4GB)
brew install --cask mactex-no-gui
# After install, update PATH
eval "$(/usr/libexec/path_helper)"
# Or open a new terminal
Unicode character errors (box-drawing, arrows, emojis):
# Use xelatex instead of pdflatex
export PATH="/Library/TeX/texbin:$PATH"
pandoc input.md --pdf-engine=xelatex -o output.pdf
No LaTeX available - Use HTML print-to-PDF workflow:
pandoc input.md -s --toc -o output.html
open output.html
# Then Cmd+P > Save as PDF
# Verify pandoc installation
pandoc --version | head -1
# Test basic conversion
echo "# Test\n\nHello **world**" | pandoc -f markdown -t html
Weekly Installs
116
Repository
GitHub Stars
6
First Seen
Feb 4, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli113
codex113
opencode112
cursor111
github-copilot111
kimi-cli110
Lark Skill Maker 教程:基于飞书CLI创建AI技能,自动化工作流与API调用指南
39,100 周安装
散文风格诊断技能:识别小说句子写作问题,提升写作质量与故事表现力
150 周安装
GitHub Copilot CLI 委托技能:非交互式命令、模型选择与安全权限指南
153 周安装
Claude Code 多智能体编排系统 - 基于 Git 的轻量级任务追踪与工作流管理
150 周安装
Next.js useSearchParams Suspense 模式详解:解决URL参数读取与服务器端渲染问题
151 周安装
财报交易分析器 - 五因子评分系统,精准识别财报后动量交易机会
157 周安装
Vercel AI SDK v6 完整指南:实现聊天、工具调用、结构化输出与智能体
150 周安装
| Use FILE for styling (docx/odt) |
--template=FILE | Use custom template |
--highlight-style=STYLE | Syntax highlighting (pygments, tango, etc.) |
--number-sections | Number section headings |
-f FORMAT | Input format (if not auto-detected) |
-t FORMAT | Output format (if not auto-detected) |
| RST | rst |
| EPUB | epub |
| ODT | odt |
| RTF | rtf |