The HTVG CLI provides commands for compiling JSON element trees into SVG graphics.
compile
Compile an HTVG document to SVG format.
htvg compile <input> [OPTIONS]
Input JSON file path. Can be either:
- A self-contained document with
meta and content fields
- A bare element tree (uses default metadata)
Options
Output SVG file path. If not specified, outputs to stdout.Aliases: -o
Override the output width in pixels. Takes precedence over width specified in document metadata.Aliases: -w
Pretty-print the SVG output with indentation and line breaks.
Examples
Compile to stdout:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 600">...</svg>
Compile to file:
htvg compile input.json --output output.svg
Wrote output.svg (800x600)
Override width:
htvg compile input.json -w 1200 -o wide.svg
Wrote wide.svg (1200x900)
Pretty-print output:
htvg compile input.json --pretty
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 600">
<rect x="0" y="0" width="100" height="100" fill="#ff0000"/>
</svg>
Self-contained document:
{
"meta": {
"width": 800
},
"content": {
"type": "rect",
"width": 100,
"height": 100
}
}
Bare element (fallback):
{
"type": "rect",
"width": 100,
"height": 100
}
Error Handling
The command exits with status code 1 on errors:
htvg compile nonexistent.json
Error reading nonexistent.json: No such file or directory
htvg compile invalid.json
Compile error: unexpected token at line 1 column 5
version
Print version information.
Examples
Alternatively, use the standard --version flag: