question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support API in nodejs

See original GitHub issue

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 )

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nkuehncommented, 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 .

0reactions
jgreywolfcommented, Feb 25, 2021

Closing as wont fix

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a Secure Node.js REST API - Toptal
Creating a Secure REST API in Node.js · Request with the appropriate data for creating a user · Confirmation response with userID ·...
Read more >
Node.js - RESTful API - Tutorialspoint
Node.js - RESTful API, REST stands for REpresentational State Transfer. REST is web standards based architecture and uses HTTP Protocol.
Read more >
How to Build REST API with Node.js from Scratch - Edureka
This article on Building a REST API with Node.js will give you a step by step demostration for creating a CRUD application using...
Read more >
Node-API | Node.js v19.3.0 Documentation
Node-API is a C API that ensures ABI stability across Node.js versions and different compiler levels. A C++ API can be easier to...
Read more >
Consume and provide APIs with API Connect and Node.js
Learn how both API providers and API consumers interact with API Connect as an API hub. Learn how API providers can use Node.js...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found