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

Support API in nodejs #1183

Closed
jiangtj opened this issue Jan 7, 2020 · 5 comments
Closed

Support API in nodejs #1183

jiangtj opened this issue Jan 7, 2020 · 5 comments
Labels
Status: Wont Fix Type: Other Not an enhancement or a bug

Comments

@jiangtj
Copy link

jiangtj commented Jan 7, 2020

Describe the solution you'd like

I see that mermaid provides API to operate on the browser side, but why similar API isn't provided in nodejs?

For example:

const mermaid = require('mermaid');
var renderer = new marked.Renderer();
renderer.code = function (code, language) {
    if(code.match(/^sequenceDiagram/)||code.match(/^graph/)){
        return '<div class="mermaid">'+mermaid.render(code)+'</div>';
    }
    else{
        return '<pre><code>'+code+'</code></pre>';
    }
};

Many MD renderers will provide code blocks. We only need to render them into the SVG. Compared with introducting JS in the browser, this solution can improve the efficiency of page loading (after all, it has been processed in node )

@jiangtj jiangtj added Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request labels Jan 7, 2020
@klemmchr
Copy link
Member

klemmchr commented Jan 7, 2020

Mermaid relies on the browser to generate diagrams so you won’t be able to use it without browser.

@klemmchr klemmchr added Type: Other Not an enhancement or a bug and removed Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request labels Jan 7, 2020
@vcarl
Copy link

vcarl commented Jan 17, 2020

I pretty briefly dug into this because I was alarmed to find that gatsby-remark-mermaid was rendering them using puppeteer, and I was surprised to find such a heavy reliance on DOM APIs to construct the final SVGs. This seems like it would essentially boil down into a full rewrite, at least of the rendering logic, because of how thoroughly mermaid assumes it's in a browser environment.

@nkuehn
Copy link

nkuehn commented May 6, 2020

I haven't tried it, but JsDOM ( https://github.com/jsdom/jsdom ) provides a fairly complete DOM API implementation for node.js without having to use the full browser stack including the renderer and CSS implementation (like puppeteer).

So in its simplest form you could try to pass a JsDOM <div> element to mermaid API as that last parameter that allows to inject an own element to be used for the rendering.

Edits: Issue #559 covers the discussion but was auto-closed by the bot due to inactivity. summary: JsDom does not work because the layout algorithm relies on letting the browser engine calculate the size of the elements. Since any custom CSS is supported and the layout is SVG, i.e. absolute pixels it looks the mermaid architecture is actually constrained to browser engines .

@mithray
Copy link

mithray commented Oct 18, 2020

Edits: Issue #559 covers the discussion but was auto-closed by the bot due to inactivity. summary: JsDom does not work because the layout algorithm relies on letting the browser engine calculate the size of the elements. Since any custom CSS is supported and the layout is SVG, i.e. absolute pixels it looks the mermaid architecture is actually constrained to browser engines .

Such a shame. I can't use this for server side rendering. I've tried the CLI that uses puppeteer and it seems hacky at best. Huge resource requirement and it freezes my machine. I'll have to stick with chartjs.

@jgreywolf
Copy link
Contributor

Closing as wont fix

@github-actions github-actions bot locked and limited conversation to collaborators Feb 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Status: Wont Fix Type: Other Not an enhancement or a bug
Projects
None yet
Development

No branches or pull requests

6 participants