Documentation Index
Fetch the complete documentation index at: https://mintlify.com/coleam00/excalidraw-diagram-skill/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The render pipeline converts.excalidraw JSON files into high-quality PNG images using a Python script that orchestrates Playwright, headless Chromium, and the Excalidraw library.
Location: references/render_excalidraw.py
Quick Start
First-Time Setup
Basic Usage
<filename>.png next to the source .excalidraw file.
Advanced Options
Path to the
.excalidraw JSON file to renderOutput PNG path (default: same name as input with
.png extension)Device scale factor for high-DPI rendering (2 = retina quality)
Maximum viewport width in pixels
Architecture
Pipeline Stages
1. Validation
The script validates the Excalidraw JSON structure before attempting to render:references/render_excalidraw.py
typefield must be"excalidraw"elementsarray must exist and be a valid array- At least one element must be present (no empty diagrams)
2. Bounding Box Calculation
The script computes the smallest rectangle that contains all diagram elements:references/render_excalidraw.py
- Skips deleted elements (
isDeleted: true) - Handles arrows/lines by iterating through their
pointsarray - Adds 80px padding on all sides
- Falls back to 800×600 if no elements found
3. Viewport Configuration
references/render_excalidraw.py
- Calculates natural diagram dimensions from bounding box
- Adds 80px padding on all sides
- Caps width at
max_width(default 1920px) - Ensures minimum height of 600px
4. Browser Rendering
The script uses Playwright to control a headless Chromium browser:references/render_excalidraw.py
- Launch headless Chromium with specified viewport and scale
- Load
render_template.htmlfrom the same directory - Wait for Excalidraw library to load from esm.sh CDN
- Call
window.renderDiagram()with the JSON data - Wait for render completion signal
- Screenshot the SVG element (not the whole page)
5. HTML Template
The template (render_template.html) provides a minimal HTML page that loads Excalidraw:
references/render_template.html
- Loads
@excalidraw/excalidrawfrom esm.sh CDN (no build step) - Forces white background for consistent exports
- Sets coordination flags (
__moduleReady,__renderComplete) for Python to await - Returns structured success/error response
Dependencies
Frompyproject.toml:
references/pyproject.toml
- Python 3.11+
- Playwright Python library
- Chromium browser (installed via
playwright install chromium) - Internet connection (to load Excalidraw library from esm.sh)
Error Handling
The script provides clear error messages for common failure modes:Invalid JSON
Invalid Excalidraw Structure
Playwright Not Installed
Chromium Not Installed
Render Failure
Missing SVG Element
Output Format
On success, the script prints the output path to stdout:Performance Characteristics
- Cold start: ~3-5 seconds (browser launch + library load)
- Warm render: ~1-2 seconds (subsequent renders in same process)
- Memory: ~150-300 MB per browser instance
- Network: Downloads Excalidraw library (~500KB) on first page load
Troubleshooting
Script hangs at 'waiting for module'
Script hangs at 'waiting for module'
The template can’t load the Excalidraw library from esm.sh. Check your internet connection or firewall settings.
Rendered image is clipped or cut off
Rendered image is clipped or cut off
The bounding box calculation may not account for all elements. Try increasing the
--width parameter or checking for elements with unusual coordinate values.Text looks blurry
Text looks blurry
Increase the
--scale parameter. Default is 2 (retina quality). Try --scale 3 for even sharper text.Colors look different than in Excalidraw editor
Colors look different than in Excalidraw editor
The render uses Excalidraw’s
exportToSvg function, which may render colors slightly differently than the interactive editor. This is expected behavior.Integration with Workflow
The render pipeline is a mandatory step in the diagram creation workflow (see Quality Checklist):SKILL.md for the complete validation loop.