export-diagram
Export a diagram-design HTML file to .svg and .png next to the source
Install
Copy this folder into your Claude Code project (needs Node.js):
curl -fsSL --create-dirs -o .claude/commands/export-diagram.md https://raw.githubusercontent.com/cathrynlavery/diagram-design/HEAD/commands/export-diagram.mdOr install it for every project:
curl -fsSL --create-dirs -o ~/.claude/commands/export-diagram.md https://raw.githubusercontent.com/cathrynlavery/diagram-design/HEAD/commands/export-diagram.mdFile content
Made by its original authors and shared under MIT. We show it unchanged, with credit and a link to the source. Source β
--- description: Export a diagram-design HTML file to .svg and .png next to the source argument-hint: <html-file> [--svg-only|--png-only] [--scale=N] [--output=<path>] [--registry] allowed-tools: - Read - Write - Edit - Bash - Glob --- Export the diagram HTML at `$1` to `.svg` and/or `.png`, following the procedure documented in [`skills/diagram-design/references/export.md`](../skills/diagram-design/references/export.md). Treat that reference as the source of truth β don't reimplement the logic here. Run the packaged `skills/diagram-design/scripts/export_svg.py` and `skills/diagram-design/scripts/export_png.py` helpers for the requested formats. If `--registry` is present, also follow [`skills/diagram-design/references/export-registry.md`](../skills/diagram-design/references/export-registry.md) to emit the metadata sidecar β a separate procedure from the SVG/PNG rasterization above. Full argument string: `$ARGUMENTS` ## Defaults - **With no format flag (nothing, or only `--scale`/`--output`) and no `--registry`:** produce **both** `.svg` and `.png` next to the source (e.g. `diagram.html` β `diagram.svg` + `diagram.png`). `--svg-only` or `--png-only` restricts the image output to that one format. - PNG renders at `device_scale_factor=2`. - **`--registry` given by itself, with neither `--svg-only` nor `--png-only` also present, produces *only* the registry JSON.** The SVG/PNG defaults above do not also apply, and Playwright is never required for a registry-only call. To get an image alongside the registry, add `--svg-only` or `--png-only` explicitly. ## Flags - `--svg-only` β emit only the SVG. Skip Playwright entirely. - `--png-only` β emit only the PNG. - `--scale=N` β override the PNG device scale factor with a finite number from `1` to `4`, including fractional values such as `1.25`. Default `2`. - `--output=<path>` β override the output base path; the format extension is appended. Applies to both formats when both are produced. - `--registry` β emit `<basename>.registry.json`, a metadata sidecar of every block's `data-block-*` attributes. Follows [`skills/diagram-design/references/export-registry.md`](../skills/diagram-design/references/export-registry.md), a procedure independent of the SVG/PNG rasterization above β it never needs Playwright. Used alone (see Defaults), it is the *only* output produced. Combine with `--svg-only` or `--png-only` to also produce an image in the same call. ## Required behaviour 1. **No source path provided** β ask the user which `.html` file to export. Don't guess. 2. **Source is `assets/index.html`** (the gallery, multiple SVGs in one file) β refuse and ask which specific diagram file. Per the reference's edge-case section. 3. **Source has no `<svg>` block** β refuse and tell the user; don't write anything. 4. **PNG requested but Playwright not installed** β surface the install instruction from the reference verbatim and stop. Do **not** auto-install. 5. **PNG requested with a non-numeric or non-finite `--scale`, or a value outside the inclusive 1β4 range** β reject. Fractional values within that range are valid. 6. **Both `--svg-only` and `--png-only` supplied** β reject them as mutually exclusive. 7. **`--registry` requested but source has no `data-block-id` attributes** β refuse and tell the user; don't emit an empty or partial registry file. Per the export-registry reference's edge-case section. 8. **`--registry` is the only flag given** (no `--svg-only`/`--png-only`) β emit only the registry JSON. Do not also produce SVG/PNG, and do not check for Playwright β a registry-only call must succeed on a host that doesn't have it installed at all. After producing the outputs, report the file paths and sizes back to the user.