mermaid.cli icon indicating copy to clipboard operation
mermaid.cli copied to clipboard

Read in the diagram as a string instead of a .mmd file?

Open Schachte opened this issue 6 years ago • 3 comments

I'm using Node. I'm wondering how I can have the prorgam read in my string instead of specifying a file? I have the string in memory and would prefer to just use it directly somehow instead of writing it to a file.

Schachte avatar Apr 14 '19 22:04 Schachte

I guess a way to implement is read from console stdin, GraphViz uses it.

sdcb avatar Jun 21 '19 03:06 sdcb

@Schachte, if you write a Node.js program yourself, you can use the render method from mermaidAPI. It expects a string with the graph definition.

If you want to use the mmdc script with the standard input, you'd need add the support for it. For example, if -- occurs on the command line, read the graph definition from the standard input. Or even do it by default if the file name is missing, instead of printing a failure.

prantlf avatar Oct 06 '19 08:10 prantlf

PR #65 introduces support for standard input and output, if input or output files are not provided. It can be used on the command line or in a shell script to echo a string with the graph definition to the mmdc script.

prantlf avatar Oct 06 '19 12:10 prantlf

Development has moved to the https://github.com/mermaid-js/mermaid-cli repo, please re-open your issue there if it's still relevant. The package has also been renamed on NPM to @mermaid-js/mermaid-cli, so you may need to run npm uninstall mermaid.cli && npm install @mermaid-js/mermaid-cli to get the latest version of this package.

@Schachte, if you write a Node.js program yourself, you can use the render method from mermaidAPI. It expects a string with the graph definition.

@mermaid-js/mermaid-cli supports a Node.JS API too, so you don't need to worry about creating a browser context or creating any files.

If you want to use the mmdc script with the standard input, you'd need add the support for it. For example, if -- occurs on the command line, read the graph definition from the standard input. Or even do it by default if the file name is missing, instead of printing a failure.

@mermaid-js/mermaid-cli currently can read inputs from standard input, but there's currently no support for writing to standard output. Pull requests are welcome though!

aloisklink avatar Jul 21 '23 23:07 aloisklink