Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mermaid without browser #260

Closed
tylerlong opened this issue Nov 23, 2015 · 10 comments
Closed

mermaid without browser #260

tylerlong opened this issue Nov 23, 2015 · 10 comments

Comments

@tylerlong
Copy link
Collaborator

I want to do it in pure node.js:

var mermaidAPI = require('mermaid').mermaidAPI;
var graphDefinition = 'graph TB\na-->b';
var graph = mermaidAPI.render(graphDefinition);
console.log(graph);

Currently it is not possible: https://github.com/knsv/mermaid/blob/master/src/mermaidAPI.js#L486

if (typeof document === 'undefined') {
// Todo handle rendering serverside using phantomjs
}

@knsv
Copy link
Collaborator

knsv commented Nov 24, 2015

I agree. That would be a good function. It would impact the CLI in a positive way. It comes down to providing a document containing a DOM object which is used by d3.

I have not worked so much directly with for instance phantomJS. I'll put this as help wanted for now! Lets hope that someone are interested in coding this.

@tylerlong
Copy link
Collaborator Author

tylerlong commented Dec 8, 2015

I just have an idea: https://github.com/mhart/react-server-example
React support server side DOM rendering. Can we use React as the 'browser' ?

I have checked the phantomJS project. It seems that it is not being actively developed. It doesn't support OS 10.11 at the moment.

@akuma
Copy link

akuma commented Jun 12, 2016

+1

@popul
Copy link

popul commented Oct 25, 2016

It's not about the issue, but i made a webpack loader that helps to generate PNG files from mermaid diagrams. https://github.com/popul/mermaid-loader

It can help :)

@tylerlong
Copy link
Collaborator Author

tylerlong commented Nov 10, 2016

@popul, could you please explain how do you turn *.mmd into png? I checked your code but I really don't get it.

Are you using phantomjs to do the trick or something else?

Update: it seems that node_modules/.bin/mermaid is able to create png

@popul
Copy link

popul commented Nov 15, 2016

I just run Mermaid CLI into the webpack loader.

https://github.com/popul/mermaid-loader/blob/master/index.js#L8

...
var binPath = './node_modules/.bin/mermaid';
...

https://github.com/popul/mermaid-loader/blob/master/index.js#L87

...
childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) {
...

I tried to generate png server side, but dagre-d3 seems to be not compatible without a browser.

@wreulicke
Copy link

wreulicke commented Aug 26, 2017

I removed phantomjs-prebuilt in my fork, and added puppeteer.
How is this?

wreulicke@c18c8aa

But, this uses async-await, so this only runs in latest version of Node. (TODO use babel?)

@tylerlong
Copy link
Collaborator Author

Puppeteer is good! I like it.

I am planning to to replace Phantom with puppeteer in future official release.

@tylerlong
Copy link
Collaborator Author

Closing it, since I am the creator of this issue.

mgenereu pushed a commit to mgenereu/mermaid that referenced this issue Jun 25, 2022
…yarn/develop/eslint-7.30.0

Bump eslint from 7.29.0 to 7.30.0
@KartikSoneji
Copy link

KartikSoneji commented Aug 2, 2022

Hi, can this issue be reopened?
Puppeteer too launches a headless chrome instance in the background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants