File Converter
Overview
Convert files between formats across three categories: documents, data files, and images. Generate Python code dynamically for each conversion request, selecting appropriate libraries and handling edge cases.
Conversion Categories
Documents
| From |
To |
Recommended Library |
| Markdown |
HTML |
markdown or mistune |
| HTML |
Markdown |
markdownify or html2text |
| HTML |
PDF |
weasyprint or pdfkit (requires wkhtmltopdf) |
| PDF |
Text |
pypdf or pdfplumber |
| DOCX |
Markdown |
mammoth |
| DOCX |
PDF |
docx2pdf (Windows/macOS) or LibreOffice CLI |
| Markdown |
PDF |
Convert via HTML first, then to PDF |
Data Files
| From |
To |
Recommended Library |
| JSON |
YAML |
pyyaml |
| YAML |
JSON |
pyyaml |
| JSON |
CSV |
pandas or stdlib csv + json |
| CSV |
JSON |
pandas or stdlib csv + json |
| JSON |
TOML |
tomli/tomllib (read) + tomli-w (write) |
| XML |
JSON |
xmltodict |
| JSON |
XML |
dicttoxml or xmltodict.unparse |
Images
| From |
To |
Recommended Library |
| PNG/JPG/WebP/GIF |
Any raster |
Pillow (PIL) |
| SVG |
PNG/JPG |
cairosvg or svglib + reportlab |
| PNG |
SVG |
potrace (CLI) for tracing, limited fidelity |
Workflow
- Identify source format (from file extension or user statement)
- Identify target format
- Check
references/ for format-specific guidance
- Generate conversion code using recommended library
- Handle edge cases (encoding, transparency, nested structures)
- Execute conversion and report results
Quick Patterns
Data: JSON to YAML
import json
import yaml
with open("input.json") as f:
data = json.load(f)
with open("output.yaml", "w") as f:
yaml.dump(data, f, default_flow_style=False, allow_unicode=True)
Data: CSV to JSON
import csv
import json
with open("input.csv") as f:
reader = csv.DictReader(f)
data = list(reader)
with open("output.json", "w") as f:
json.dump(data, f, indent=2)
Document: Markdown to HTML
import markdown
with open("input.md") as f:
md_content = f.read()
html = markdown.markdown(md_content, extensions=["tables", "fenced_code"])
with open("output.html", "w") as f:
f.write(html)
Image: PNG to WebP
from PIL import Image
img = Image.open("input.png")
img.save("output.webp", "WEBP", quality=85)
Image: SVG to PNG
import cairosvg
cairosvg.svg2png(url="input.svg", write_to="output.png", scale=2)
Resources
Detailed guidance for complex conversions is in references/:
references/document-conversions.md - PDF handling, encoding issues, styling preservation
references/data-conversions.md - Schema handling, type coercion, nested structures
references/image-conversions.md - Quality settings, transparency, color profiles
Consult these references when handling edge cases or when the user has specific quality/fidelity requirements.
1---2name: file-converter3description: This skill handles file format conversions across documents (PDF, DOCX, Markdown, HTML, TXT), data files (JSON, CSV, YAML, XML, TOML), and images (PNG, JPG, WebP, SVG, GIF). Use when the user requests converting, transforming, or exporting files between formats. Generates conversion code dynamically based on the specific request.4---56# File Converter78## Overview910Convert files between formats across three categories: documents, data files, and images. Generate Python code dynamically for each conversion request, selecting appropriate libraries and handling edge cases.1112## Conversion Categories1314### Documents1516| From | To | Recommended Library |17|------|-----|---------------------|18| Markdown | HTML | `markdown` or `mistune` |19| HTML | Markdown | `markdownify` or `html2text` |20| HTML | PDF | `weasyprint` or `pdfkit` (requires wkhtmltopdf) |21| PDF | Text | `pypdf` or `pdfplumber` |22| DOCX | Markdown | `mammoth` |23| DOCX | PDF | `docx2pdf` (Windows/macOS) or LibreOffice CLI |24| Markdown | PDF | Convert via HTML first, then to PDF |2526### Data Files2728| From | To | Recommended Library |29|------|-----|---------------------|30| JSON | YAML | `pyyaml` |31| YAML | JSON | `pyyaml` |32| JSON | CSV | `pandas` or stdlib `csv` + `json` |33| CSV | JSON | `pandas` or stdlib `csv` + `json` |34| JSON | TOML | `tomli`/`tomllib` (read) + `tomli-w` (write) |35| XML | JSON | `xmltodict` |36| JSON | XML | `dicttoxml` or `xmltodict.unparse` |3738### Images3940| From | To | Recommended Library |41|------|-----|---------------------|42| PNG/JPG/WebP/GIF | Any raster | `Pillow` (PIL) |43| SVG | PNG/JPG | `cairosvg` or `svglib` + `reportlab` |44| PNG | SVG | `potrace` (CLI) for tracing, limited fidelity |4546## Workflow47481. Identify source format (from file extension or user statement)492. Identify target format503. Check `references/` for format-specific guidance514. Generate conversion code using recommended library525. Handle edge cases (encoding, transparency, nested structures)536. Execute conversion and report results5455## Quick Patterns5657### Data: JSON to YAML5859```python60import json61import yaml6263with open("input.json") as f:64 data = json.load(f)6566with open("output.yaml", "w") as f:67 yaml.dump(data, f, default_flow_style=False, allow_unicode=True)68```6970### Data: CSV to JSON7172```python73import csv74import json7576with open("input.csv") as f:77 reader = csv.DictReader(f)78 data = list(reader)7980with open("output.json", "w") as f:81 json.dump(data, f, indent=2)82```8384### Document: Markdown to HTML8586```python87import markdown8889with open("input.md") as f:90 md_content = f.read()9192html = markdown.markdown(md_content, extensions=["tables", "fenced_code"])9394with open("output.html", "w") as f:95 f.write(html)96```9798### Image: PNG to WebP99100```python101from PIL import Image102103img = Image.open("input.png")104img.save("output.webp", "WEBP", quality=85)105```106107### Image: SVG to PNG108109```python110import cairosvg111112cairosvg.svg2png(url="input.svg", write_to="output.png", scale=2)113```114115## Resources116117Detailed guidance for complex conversions is in `references/`:118119- `references/document-conversions.md` - PDF handling, encoding issues, styling preservation120- `references/data-conversions.md` - Schema handling, type coercion, nested structures121- `references/image-conversions.md` - Quality settings, transparency, color profiles122123Consult these references when handling edge cases or when the user has specific quality/fidelity requirements.