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.

add function rendering mermaid syntax to html string without replacing html objects

See original GitHub issue

I think a lot of people could possibly benefit from mermaidAPI.render() function having more flexibility when it comes to rendering options. Last two days I had to hack mermaidAPI.render() to get just rendered string (to use it with Vue.js). Here what I discovered:

  • The first time it renders correctly, each next time it raises error:
mermaidAPI.render(NaN, string, function(graph){console.log(graph)})
  • Raises error every time:
mermaidAPI.render(null, string, function(graph){console.log(graph)})
  • Sometimes raises error, sometimes not (not sure how it works):
mermaidAPI.render(undefined, string, function(graph){console.log(graph)})
  • Renders for the first call, after it raises error, that it cant find “#string” (without #string in html):
mermaidAPI.render("string", string, function(graph){console.log(graph)})
  • Raises error only if first letter of generated string is digit:
var hack = Math.random().toString(36).substring(7)
mermaidAPI.render(hack, string, function(graph){console.log(graph)})
  • We use this solution, and it’s working well so far:
var hack = Math.random().toString(36).substring(7).replace(/\d/, "a")
mermaidAPI.render(hack, string, function(graph){console.log(graph)})

Our problem: we need onclick refreshing string witch communicates well with vue.js (we pass output in callback function to vue data object. There is no mermaidAPI function for that so we had to hack render function, but it occurs it acts very unpredictable depending on what JS object is passed to the first variable.

The best possible solution would be function witch just renders the graph, without trying to replace div with given id every time called.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
tylerlongcommented, Mar 16, 2018

mermaid was not designed as a node library. So it is closely coupled to browser and DOM. The ultimate solution would be like this:

const svgString = mermaid.renderString('Your graph code here...')

And it should also work in a pure node env without browser(and will work for browser too with webpack, browerify…etc.)

Recently I’ve been thinking about it.

1reaction
strangedevcommented, Dec 8, 2021

Why is this closed? This would be a very handy function to have, as it is very complicated at the moment to get mermaid to work correctly in React.

Read more comments on GitHub >

github_iconTop Results From Across the Web

add function rendering mermaid syntax to html string without ...
Our problem: we need onclick refreshing string witch communicates well with vue.js (we pass output in callback function to vue data object.
Read more >
Rendering Mermaid Charts - Markdown Monster Documentation
Note that if using the RawHtml syntax <div class="mermaid"> , the Mermaid content between the brackets is not Html Encoded.
Read more >
mermaid - Generation of diagrams and flowcharts ... - UNPKG
This is the renderer used for transforming the documentation from markdown to html with mermaid diagrams in the html. var renderer = new...
Read more >
How to render a mermaid flowchart dynamically?
It seems, I know the answer. Look at the solution below: document.querySelector("button").addEventListener("click", (e) => { const output ...
Read more >
Mermaid: Create diagrams quickly and effortlessly
Mermaid is a tool that lets you create complicated diagrams in Markdown — it works with simple commands and an intuitive syntax.
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