name: document-to-markdown
description: Convert PDF, Office, images, HTML, and URLs to Markdown. Use for document conversion, text extraction, OCR, web scraping, RAG pipelines. Triggers: "convert to markdown", "extract text", "read PDF", "scrape URL".
license: MIT License. See LICENSE.txt for details.
compatibility: macOS, Python 3.10+, curl
metadata:
version: "1.0.0"
Document to Markdown
Convert documents and URLs to clean Markdown for LLM/RAG use.
Prerequisites (Auto-handled)
Before running any conversion, check and install dependencies if needed:
# Check if dependencies are installed, install if missing
pip show pymupdf4llm markitdown pyyaml > /dev/null 2>&1 || pip install -r ~/.claude/skills/document-to-markdown/requirements.txt
Run this check automatically before first use. Do not prompt user for installation.
Quick Start
# Single file
python scripts/gateway.py --input <file_or_url> [--json]
# Batch processing
python scripts/gateway.py --input-dir <folder> --output-dir <out> [--recursive] [--parallel 4]
Supported Inputs
| Type |
Formats |
| Documents |
PDF, DOCX, PPTX, XLSX |
| Images |
PNG, JPG, JPEG, WEBP, TIFF |
| Web |
HTML (local), URLs (http/https) |
| Text |
TXT, MD, CSV, JSON, XML |
Key Options
| Option |
Purpose |
--format human |
Clean, readable output (default) |
--format rag |
Structured output for LLM/RAG |
--json |
Structured output for agents |
--input-dir |
Batch process entire directory |
--output-dir |
Output directory for batch mode |
--recursive |
Include subdirectories in batch |
--parallel N |
Process N files concurrently |
--frontmatter |
Add YAML metadata header |
--pdf-backend marker |
For scanned PDFs (slow, 1.3GB models) |
--pdf-backend paddleocr |
For scanned PDFs + Chinese (fast, <10MB) |
--table-mode |
Enable table recognition (requires paddlex[ocr]) |
--use-gpu |
GPU acceleration for PaddleOCR |
--to-traditional |
Convert Simplified to Traditional Chinese |
--pages 1-10 |
Convert specific pages only |
Workflow
- Check dependencies (auto-install if missing)
- Run:
python scripts/gateway.py --input <path> --json
- Check JSON
success field
- If
warnings present, consider switching backend
- Read output file to present content to user
Format Selection
Default: --format human (clean, readable for humans)
Use --format rag when user prompt mentions:
- "for RAG", "for LLM", "for embedding", "for AI"
- "vector database", "chunking", "indexing"
- "給 AI 讀", "餵給模型", "向量資料庫"
| Format |
Output Style |
human |
## Title / Name (email) / clean links |
rag |
## **Title** / **Name** _email_ / full metadata |
Conditional Logic
IF warning "Complex tables detected":
→ Retry with --pdf-backend marker (slower but better tables)
IF output is empty or very short:
→ Retry with --pdf-backend marker (for scanned PDFs)
IF URL timeout:
→ Increase --url-timeout or use --url-backend markitdown
IF OCR quality poor:
→ Specify --lang for correct language
Output Format
Single file:
{"success": true, "output_path": "doc.md", "backend_used": "pymupdf4llm"}
Batch:
{"success": true, "total": 10, "converted": 9, "failed": 1, "results": [...]}
For backend details, see references/backends.md.
For troubleshooting, see references/troubleshooting.md.
1---2name: document-to-markdown3description: Convert PDF, Office, images, HTML, and URLs to Markdown. Use for document conversion, text extraction, OCR, web scraping, RAG pipelines. Triggers: "convert to markdown", "extract text", "read PDF", "s4---5
6---
7name: document-to-markdown
8description: Convert PDF, Office, images, HTML, and URLs to Markdown. Use for document conversion, text extraction, OCR, web scraping, RAG pipelines. Triggers: "convert to markdown", "extract text", "read PDF", "scrape URL".
9license: MIT License. See LICENSE.txt for details.
10compatibility: macOS, Python 3.10+, curl
11metadata:
12 version: "1.0.0"
13---
14
15# Document to Markdown
16
17Convert documents and URLs to clean Markdown for LLM/RAG use.
18
19## Prerequisites (Auto-handled)
20
21Before running any conversion, check and install dependencies if needed:
22
23```bash
24# Check if dependencies are installed, install if missing
25pip show pymupdf4llm markitdown pyyaml > /dev/null 2>&1 || pip install -r ~/.claude/skills/document-to-markdown/requirements.txt
26```
27
28Run this check automatically before first use. Do not prompt user for installation.
29
30## Quick Start
31
32```bash
33# Single file
34python scripts/gateway.py --input <file_or_url> [--json]
35
36# Batch processing
37python scripts/gateway.py --input-dir <folder> --output-dir <out> [--recursive] [--parallel 4]
38```
39
40## Supported Inputs
41
42| Type | Formats |
43|------|---------|
44| Documents | PDF, DOCX, PPTX, XLSX |
45| Images | PNG, JPG, JPEG, WEBP, TIFF |
46| Web | HTML (local), URLs (http/https) |
47| Text | TXT, MD, CSV, JSON, XML |
48
49## Key Options
50
51| Option | Purpose |
52|--------|---------|
53| `--format human` | Clean, readable output (default) |
54| `--format rag` | Structured output for LLM/RAG |
55| `--json` | Structured output for agents |
56| `--input-dir` | Batch process entire directory |
57| `--output-dir` | Output directory for batch mode |
58| `--recursive` | Include subdirectories in batch |
59| `--parallel N` | Process N files concurrently |
60| `--frontmatter` | Add YAML metadata header |
61| `--pdf-backend marker` | For scanned PDFs (slow, 1.3GB models) |
62| `--pdf-backend paddleocr` | For scanned PDFs + Chinese (fast, <10MB) |
63| `--table-mode` | Enable table recognition (requires `paddlex[ocr]`) |
64| `--use-gpu` | GPU acceleration for PaddleOCR |
65| `--to-traditional` | Convert Simplified to Traditional Chinese |
66| `--pages 1-10` | Convert specific pages only |
67
68## Workflow
69
701. Check dependencies (auto-install if missing)
712. Run: `python scripts/gateway.py --input <path> --json`
723. Check JSON `success` field
734. If `warnings` present, consider switching backend
745. Read output file to present content to user
75
76## Format Selection
77
78Default: `--format human` (clean, readable for humans)
79
80Use `--format rag` when user prompt mentions:
81- "for RAG", "for LLM", "for embedding", "for AI"
82- "vector database", "chunking", "indexing"
83- "給 AI 讀", "餵給模型", "向量資料庫"
84
85| Format | Output Style |
86|--------|-------------|
87| `human` | `## Title` / `Name (email)` / clean links |
88| `rag` | `## **Title**` / `**Name** _email_` / full metadata |
89
90## Conditional Logic
91
92```
93IF warning "Complex tables detected":
94 → Retry with --pdf-backend marker (slower but better tables)
95
96IF output is empty or very short:
97 → Retry with --pdf-backend marker (for scanned PDFs)
98
99IF URL timeout:
100 → Increase --url-timeout or use --url-backend markitdown
101
102IF OCR quality poor:
103 → Specify --lang for correct language
104```
105
106## Output Format
107
108Single file:
109```json
110{"success": true, "output_path": "doc.md", "backend_used": "pymupdf4llm"}
111```
112
113Batch:
114```json
115{"success": true, "total": 10, "converted": 9, "failed": 1, "results": [...]}
116```
117
118For backend details, see `references/backends.md`.
119For troubleshooting, see `references/troubleshooting.md`.