微算力 · API 导航与自营网关
API 接入 EN
未登录登录
📄

万能文档格式转换引擎

Pandoc · v1.0.2
办公 安全 A 级 作者 oliver-hrkltz 公开目录收录
下载 1.9k 安装 2 收藏 3.9k 浏览 34

简介

基于 Pandoc 的通用文档格式转换工具,支持 50+ 种格式互转,含 PDF/DOCX/EPUB 等,支持自定义模板与样式。

原始描述

Convert documents between formats using pandoc. Supports HTML, Markdown, DOCX, PDF, EPUB, LaTeX, ODT, RST, Org, MediaWiki, JIRA, CSV, Jupyter notebooks, and...

安装

下载 zip 解压后,把里面的文件放进你的 Agent 的 skills 目录即可使用。

给 Agent 的直链(让它自己下载安装):

Claude Code 放 ~/.claude/skills/;Codex、TypingMind 等按各自文档的 skills 目录放置。技能申请什么权限由作者决定,装前请确认。

中文使用说明 来自收录源

核心用法

Pandoc Skill 是一个封装了开源文档转换工具 Pandoc 的自动化技能,用于在各种文档格式之间进行高质量转换。该技能支持双向转换 Markdown、HTML、PDF、DOCX、EPUB、LaTeX、ODT、RST、Org、MediaWiki、JIRA、CSV、Jupyter Notebook 等 50 余种格式。

基础转换流程:通过 scripts/convert.sh 助手脚本实现自动化检测,自动识别输入/输出格式(基于文件扩展名),智能选择 PDF 引擎,并传递参数至底层 Pandoc 命令。转换过程遵循"读取源格式 → 解析为内部 AST → 写入目标格式"的三阶段模型。

关键控制点:

  • PDF 引擎选择:xelatex(Unicode/字体最优)、lualatex(复杂排版)、tectonic(自包含 TeX)、pdflatex(ASCII 文档最快)、或 HTML/CSS 引擎(weasyprint、wkhtmltopdf、prince)
  • 样式控制:CSS 用于 HTML 类输出,LaTeX 变量/模板用于 PDF,参考文档用于 DOCX/ODT
  • 增强功能:目录生成(--toc)、元数据注入(-M)、媒体提取(--extract-media)、Lua 过滤器、多文件合并

显著优点

  1. 格式覆盖全面:支持学术出版、技术文档、电子书、办公文档等全场景格式需求
  2. 转换质量高:基于 AST 的中间表示确保语义保留,非简单的文本替换
  3. 样式深度可控:从快速转换到企业级品牌定制均有对应方案
  4. 工程化封装:convert.sh 脚本自动处理引擎检测、错误提示、参数校验,降低使用门槛
  5. 多引擎 PDF 生成:针对不同场景提供 6 种 PDF 引擎选项,平衡质量、速度与资源占用

潜在缺点与局限性

  1. 外部依赖复杂:必须预装 Pandoc,PDF 生成还需额外安装 TeX 发行版或特定引擎,完整环境配置较重
  2. CSS-LaTeX 割裂:PDF 输出若使用 LaTeX 引擎则忽略 CSS,样式需用两套技术栈维护
  3. 复杂排版边界:极度复杂的页面布局、交互式 HTML 特性可能无法完美转换
  4. 字体渲染差异:跨平台字体可用性差异可能导致 PDF 字符缺失(需显式指定支持字体)

适合人群

  • 技术写作者:Markdown 源文件输出多格式分发版本
  • 学术研究者:LaTeX/Pandoc 工作流生成 PDF 论文与 HTML 预印本
  • 出版与文档工程师:批量文档格式标准化、电子书生成(EPUB)
  • 企业 IT:文档自动化流水线,品牌模板化 DOCX/PDF 输出

常规风险

  • 依赖缺失导致转换失败:未安装对应 PDF 引擎时生成 PDF 将报错
  • 样式预期落差:用户对"美观"的期望与实际模板效果不一致
  • 路径与资源引用:相对路径图片/CSS 在转换后可能失效,需使用 --self-contained 或绝对路径
  • 敏感信息泄露:模板或参考文档可能携带元数据,用于外部文件时需注意清理

该技能本身为 Pandoc 的调用封装,不引入额外网络请求或远程代码执行风险,安全性主要取决于底层 Pandoc 及 PDF 引擎的安装来源与版本。

技能正文


name: pandoc description: > Convert documents between formats using pandoc. Supports HTML, Markdown, DOCX, PDF, EPUB, LaTeX, ODT, RST, Org, MediaWiki, JIRA, CSV, Jupyter notebooks, and many more — any direction pandoc supports. Use this skill whenever the user wants to convert, transform, or export a document from one format to another, even if they don't mention pandoc explicitly. Triggers include: "convert this to PDF", "make a Word doc from this markdown", "export as EPUB", "turn this HTML into a PDF", "transform", "generate PDF", "render to", or any request involving document format conversion. Also use when the user wants to apply custom styling, add a table of contents, use a template, or set metadata during conversion. metadata: version: 1.0.2 author: Oliver Herklotz (oliver-hrkltz) homepage: https://github.com/hrkltz/pandoc-skill compatibility: > Requires: pandoc (https://pandoc.org). Optional PDF engines: xelatex (texlive-xetex, recommended for Unicode/fonts), lualatex (texlive-luatex, complex typography), tectonic (self-contained TeX workflow), pdflatex (texlive-latex-base, fastest for ASCII), weasyprint (CSS Paged Media, Python-based), wkhtmltopdf (WebKit-based HTML/CSS rendering), prince (commercial HTML/CSS renderer).

Pandoc Document Converter

Convert documents between any formats pandoc supports, with full control over styling, templates, table of contents, metadata, and PDF engine selection.

Quick Start

For most conversions, use the helper script at scripts/convert.sh:

bash <skill-dir>/scripts/convert.sh <input-file> <output-file> [options...]

The script auto-detects formats from file extensions and applies sensible defaults (standalone output, appropriate PDF engine, default LaTeX margins for LaTeX-based PDF engines). It also checks that pandoc, the input file, the output directory, and any requested PDF engine are available. Any extra arguments are passed through to pandoc.

How Conversions Work

Pandoc reads a source format into an internal AST, then writes it out in the target format. This means you can go from nearly any supported input to any supported output. The key decision points are:

  1. Input format — usually auto-detected from the file extension
  2. Output format — auto-detected from the output file extension
  3. PDF engine — for PDF output, choose between xelatex (best Unicode/font support), lualatex (strong Unicode/fonts), tectonic (self-contained TeX), pdflatex (fastest, good for ASCII-heavy docs), or HTML/CSS engines like weasyprint, wkhtmltopdf, or prince
  4. Styling — CSS for HTML-based outputs, LaTeX templates for PDF, reference docs for DOCX/ODT

Common Conversion Patterns

HTML → PDF

pandoc input.html -o output.pdf --pdf-engine=weasyprint -s

If the HTML uses external CSS, include it:

pandoc input.html -o output.pdf --pdf-engine=weasyprint -s --css=style.css

Markdown → PDF

pandoc input.md -o output.pdf --pdf-engine=xelatex -s --toc --toc-depth=3

Markdown → DOCX

pandoc input.md -o output.docx -s

To use a reference (template) document for styling:

pandoc input.md -o output.docx --reference-doc=template.docx

Markdown → HTML

pandoc input.md -o output.html -s --css=style.css --toc

DOCX → Markdown

pandoc input.docx -o output.md --extract-media=./media

Markdown → EPUB

pandoc input.md -o output.epub -s --toc --epub-cover-image=cover.jpg

LaTeX → PDF

pandoc input.tex -o output.pdf --pdf-engine=xelatex

CSV → HTML table

pandoc input.csv -o output.html -s

Styling and Appearance

CSS for HTML-based outputs

Create or use a CSS file and pass it with --css=path/to/style.css. For PDF output via weasyprint, wkhtmltopdf, or prince, CSS is respected directly. For PDF via LaTeX engines, CSS is usually ignored — use LaTeX variables or templates instead.

A sensible default stylesheet is provided at assets/default.css. Use it when the user wants a clean, readable output without specifying their own styles:

pandoc input.md -o output.html -s --css=<skill-dir>/assets/default.css

LaTeX variables for PDF styling

Control margins, fonts, and paper size without a full template:

pandoc input.md -o output.pdf --pdf-engine=xelatex \
  -V geometry:margin=1in \
  -V fontsize=12pt \
  -V mainfont="DejaVu Serif" \
  -V documentclass=article

Reference documents for DOCX/ODT

To match a corporate style, provide a reference document:

pandoc input.md -o output.docx --reference-doc=brand-template.docx

Advanced Features

Table of Contents

Add --toc and optionally --toc-depth=N (default 3):

pandoc input.md -o output.pdf --pdf-engine=xelatex -s --toc --toc-depth=2

Metadata

Set title, author, date via YAML frontmatter in the source file or via -M:

pandoc input.md -o output.pdf --pdf-engine=xelatex -s \
  -M title="My Report" -M author="Jane Doe" -M date="2026-03-15"

Filters and Lua filters

Pandoc supports filters that transform the AST. Lua filters are self-contained:

pandoc input.md -o output.pdf --lua-filter=my-filter.lua

Multiple input files

Pandoc concatenates multiple inputs:

pandoc chapter1.md chapter2.md chapter3.md -o book.pdf --pdf-engine=xelatex -s --toc

Extracting media from DOCX/EPUB

pandoc input.docx -o output.md --extract-media=./media

Troubleshooting

Problem Likely cause Fix
PDF has missing characters Font doesn't support the glyphs Use --pdf-engine=xelatex with -V mainfont="DejaVu Serif"
PDF conversion fails No compatible PDF engine installed Check which xelatex lualatex tectonic pdflatex weasyprint wkhtmltopdf prince and install one that matches your output needs
DOCX looks unstyled No reference doc Create a styled DOCX template and pass --reference-doc
HTML images missing Relative paths broken Use --self-contained to embed images as base64
CSS has no effect on PDF LaTeX PDF engine selected Use --pdf-engine=weasyprint, --pdf-engine=wkhtmltopdf, or --pdf-engine=prince
Table of contents empty No headings in source Ensure source uses # headings (Markdown) or <h1>–<h6> (HTML)

Format Reference

For a full list of supported input and output formats, see references/formats.md.

Choosing the Right Approach

When a user asks to convert a document, think about:

  1. What's the source format? Check the file extension or ask. If it's ambiguous (e.g., a .txt that's actually Markdown), specify -f markdown explicitly.
  2. What's the target format? Map the user's intent to a file extension.
  3. Does it need styling? If the user wants it to "look nice" or "be professional," add CSS (for HTML) or LaTeX variables (for PDF) or a reference doc (for DOCX).
  4. Does it need structure? TOC, numbered sections, metadata — add these when the document is long or formal.
  5. Are there images or media? Use --self-contained for HTML, --extract-media when converting from DOCX/EPUB to text formats.

Always use the helper script scripts/convert.sh as the starting point — it handles the most common gotchas automatically, picks a reasonable PDF engine, and prints recovery hints when PDF conversion fails. Add extra pandoc flags as needed for the specific use case.

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

其他来源收录

同一技能在不同目录的原始页面:

标签

document-conversionpandocpdf-generationmarkdownlatexepubdocxhtmlpublishingautomation

同类 Skill