mermaid-js / mermaid-cli

Command line tool for the Mermaid library
MIT License
2.53k stars 243 forks source link

Write output to stdout #683

Closed nichtich closed 3 months ago

nichtich commented 7 months ago

Is your feature request related to a problem? Please describe.

SVG output should be pipe-able.

Describe the solution you'd like

mmdc -i input.mmd -o - # emit SVG by default
mmdc -i input.mmd -e pdf -o - # emit PDF (if possible, I only need SVG)

Describe alternatives you've considered

I tried process substitution:

mmdc -i input.mmd -o >( tee output.svg )

but mmdc complains because the temporary output file in /dev/fd lacks file extension.

Manually creating a named pipe with mkfifo works, but this requires a more complex bash script:

mkfifo tmp.svg
cat tmp.svg | tee output.svg
mmdc -i input.mmd -o tmp.svg
rm tmp.svg
00dani commented 5 months ago

My attempt was to use mmdc -o /dev/stdout, but that has the same problem process substitution does: no file extension. Support for -o - to write to stdout would definitely be the cleanest solution here.

I don't think there's any reason to restrict -o - to SVG output only, since the -e flag already exists. A command line like mmdc -o - -e png | imgcat should work for example.