Get the FREE Ultimate OpenClaw Setup Guide →

file-converter

Scanned
npx machina-cli add skill aiskillstore/marketplace/file-converter --openclaw
Files (1)
SKILL.md
3.5 KB

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

FromToRecommended Library
MarkdownHTMLmarkdown or mistune
HTMLMarkdownmarkdownify or html2text
HTMLPDFweasyprint or pdfkit (requires wkhtmltopdf)
PDFTextpypdf or pdfplumber
DOCXMarkdownmammoth
DOCXPDFdocx2pdf (Windows/macOS) or LibreOffice CLI
MarkdownPDFConvert via HTML first, then to PDF

Data Files

FromToRecommended Library
JSONYAMLpyyaml
YAMLJSONpyyaml
JSONCSVpandas or stdlib csv + json
CSVJSONpandas or stdlib csv + json
JSONTOMLtomli/tomllib (read) + tomli-w (write)
XMLJSONxmltodict
JSONXMLdicttoxml or xmltodict.unparse

Images

FromToRecommended Library
PNG/JPG/WebP/GIFAny rasterPillow (PIL)
SVGPNG/JPGcairosvg or svglib + reportlab
PNGSVGpotrace (CLI) for tracing, limited fidelity

Workflow

  1. Identify source format (from file extension or user statement)
  2. Identify target format
  3. Check references/ for format-specific guidance
  4. Generate conversion code using recommended library
  5. Handle edge cases (encoding, transparency, nested structures)
  6. 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.

Source

git clone https://github.com/aiskillstore/marketplace/blob/main/skills/89jobrien/file-converter/SKILL.mdView on GitHub

Overview

File Converter handles conversions across documents, data files, and images. It dynamically generates Python code for each request, selecting the right libraries (markdown, weasyprint, pypdf, mammoth, pyyaml, Pillow, cairosvg, etc.) and addressing edge cases like encoding and fidelity.

How This Skill Works

The tool first identifies the source and target formats from the file or user input, then consults format guidance in references/ to select a suitable library. It emits Python code tailored to the specific conversion and executes it, handling edge cases such as encoding, metadata, and nested structures before producing the output.

When to Use It

  • Convert Markdown to HTML for web pages
  • Convert JSON to YAML for config files
  • Convert DOCX to PDF for distribution
  • Convert PNG/JPEG/WebP to another raster format for compatibility
  • Convert CSV to JSON for data interchange

Quick Start

  1. Step 1: Provide a source file and a target format (e.g., input.json -> YAML).
  2. Step 2: The system analyzes formats and selects the recommended library.
  3. Step 3: Run the generated Python script to perform the conversion and inspect the output.

Best Practices

  • Always identify source and target formats by extension or explicit user intent
  • Check references/ for format-specific guidance and edge cases
  • Prefer using libraries that preserve encoding and Unicode correctly
  • Test the output and validate with basic round-trips when possible
  • Document the generated code and library versions used

Example Use Cases

  • JSON to YAML using PyYAML
  • CSV to JSON using pandas or csv+json stdlib
  • Markdown to HTML using markdown or mistune
  • HTML to PDF using WeasyPrint or wkhtmltopdf
  • PNG to WebP using Pillow

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers