Mermaid.js with Node.js - Dynamically generation

25
January 25, 2020, at 11:50 PM

I am working with Mermaid.js to general a Class Diagram for my hobby project.

I am facing a very basic issue, which I cannot figure out how should I approach it.

Basically, I have the structure generated, but when I push it to the view, it is rendered with double quotes and also the '\n' is showing as well.

Node.js

let unique_Object = _.groupBy(json_result,'ChildRelationship')
let chart_schema = "classDiagram\n"
Object.keys(unique_Object).forEach(function (item){
   chart_schema = chart_schema + objectName + " <|-- " + item + "\n"
})
return chart_schema

Koa Route

.get('getD', '/getD', async (ctx) => {
   try {
      const result = await util.get_childRelationship()
      return ctx.render('test',{
         object: result
      })
   } catch (error) {
      console.error(error)
   }
})

View

<div class="mermaid" id="mermaid">
    <%- chart %>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.4.4/mermaid.min.js"></script>
<script> mermaid.mermaidAPI.initialize({
    startOnLoad: true
});</script>

View Result

"classDiagram\nParent <|-- Joe\n"

The browser is ignoring the \n.

If anyone has any idea?

READ ALSO
Kindly help me regarding this Python query [closed]

Kindly help me regarding this Python query [closed]

Want to improve this question? Update the question so it focuses on one problem only by editing this post

20
How to stop default scrolling to current time in React Date Picker?

How to stop default scrolling to current time in React Date Picker?

In react Date picker i have chosen only showTimeSelect and showTimeSelectOnly optionIts working but in time drop down always its scrolling to current time

53
How does calling &ldquo;setState&rdquo; as a callback in a function, without any new state value, successfully update the state?

How does calling “setState” as a callback in a function, without any new state value, successfully update the state?

I saw this code snippet recently, and am wondering how the state variable actually gets updated hereThis is the authentication state observer used in firebase authentication to determine if a user is signed in (docs reference)

55
Reading images from remote link instead of the FileReader to perform image compression based on JIC

Reading images from remote link instead of the FileReader to perform image compression based on JIC

I am experimenting with JIC (Javascript Image Compressor by brunobar79 and am trying to visually compress images by using a slider directly on the pageI've been expanding on the demo provided and so far I'm able to upload a local image using the FileReader...

49