ClawSkills logoClawSkills

md-to-office

使用 pandoc 命令行工具将 Markdown 文件转换为 PDF 文件。当用户要求将 .md 或 markdown 文件转换为 .pdf 文件时使用。

介绍

# Local Pandoc Conversion Skill

该技能使用 `pandoc` 命令行实用工具在多种标记格式之间转换文档。

## 基本用法

`pandoc` 命令的基本结构如下:

```bash pandoc [options] [input-file]… ```

### 简单转换

要将 Markdown 文件转换为 HTML:

```bash pandoc -o output.html input.md ```

### 指定格式

虽然 `pandoc` 可以根据文件扩展名推断格式,但您可以使用 `-f`(from,从)和 `-t`(to,到)标志显式指定。

```bash # Convert HTML to Markdown pandoc -f html -t markdown input.html ```

### 独立文档

要创建一个包含适当页眉和页脚的完整文档(例如,一个完整的 HTML 文件),请使用 `-s` 或 `--standalone` 标志。

```bash pandoc -s -o output.html input.md ```

## 高级示例

以下示例摘自官方 Pandoc 用户指南。

### PDF 输出

要创建 PDF,`pandoc` 通常使用 LaTeX 引擎。请确保已安装相应的引擎。

```bash # Basic PDF creation pandoc input.md -o output.pdf

# Control PDF engine and style via variables pandoc input.md -o output.pdf --pdf-engine=xelatex -V geometry:margin=1in -V fontsize=12pt ```

### 文档结构与元数据

Pandoc 可以自动生成目录并使用文档元数据。

```bash # Create a document with a Table of Contents (up to level 3 headings) pandoc --toc --toc-depth=3 -o output.docx input.md

# Set metadata fields from the command line pandoc -M title:"My Report" -M author:"Galactus" -o output.pdf input.md ```

### 模板和样式

您可以使用模板和其他选项来控制最终输出的结构和样式。

```bash # Use a custom template for HTML output pandoc -s --template=my-template.html -o output.html input.md

# For HTML output, link to a custom CSS file pandoc -s --css=styles.css -o output.html input.md

# For DOCX output, use a reference document for styling pandoc --reference-doc=reference.docx -o output.docx input.md ```

### 从 Web 读取

Pandoc 可以直接获取并转换来自 URL 的内容。

```bash pandoc -f html -t markdown https://www.fsf.org ```

### 其他有用选项

```bash # Preserve tabs instead of converting them to spaces pandoc --preserve-tabs ...

# Control line wrapping in the output source code pandoc --wrap=none ...

# Shift heading levels (e.g., make all H1s into H2s, H2s into H3s) pandoc --shift-heading-level-by=1 ... ``` 这份增强的文档为使用 `pandoc` 提供了更坚实的基础。

更多产品