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.

MermaidJS: Suppress using HTML tags in SVG documents

See original GitHub issue

MermaidJS, by default, uses tags that only render inside of web browsers (foreignObject and div). A number of issues have been logged against MermaidJS to address this problem:

Issue 2688 recommends:

{
    "flowchart": {
        "htmlLabels": "false"
    }
}

What would be involved in revising Kroki to configure MermaidJS to avoid using HTML tags for all diagrams so as to generate more conformant SVG documents?

KeenWrite invokes Kroki using an HTTP GET request, so ideally the server could be configured to set htmlLabels to false, which would then allow KeenWrite to display the SVG files without modification:

https://github.com/DaveJarvis/keenwrite/blob/6fa925d27bbec807fc4419454aa81941524f889f/src/main/java/com/keenwrite/preview/DiagramUrlGenerator.java#L26

Alternatively, it looks like Kroki supports HTTP GET URL parameters for setting options:

https://docs.kroki.io/kroki/setup/usage/#_options

See also:

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Mogzttercommented, Dec 14, 2022

I was referring to the “internal” requests between Kroki containers. We will still support all the options when sending a request to the gateway server.

1reaction
Mogzttercommented, Dec 14, 2022

Kroki supports diagram options: https://docs.kroki.io/kroki/setup/usage/#_options

Currently, the gateway server calls the mermaid companion container with the diagram options but the mermaid service does not use them.

We are using the following default Mermaid configuration: https://github.com/yuzutech/kroki/blob/main/mermaid/src/task.js

So what we need to do is:

  1. establish a naming convention for Mermaid configuration (since they are using nested name)
  2. establish a convention to infer the type of the value (array, boolean, number…)
  3. get the diagram options from the query parameters in: https://github.com/yuzutech/kroki/blob/main/mermaid/src/index.js#L12
  4. merge the configuration with the default configuration: https://github.com/yuzutech/kroki/blob/main/mermaid/src/task.js

As a workaround, I think you can use a directive:

%%{ init: { "flowchart": { "htmlLabels": false } }%%

https://mermaid-js.github.io/mermaid/#/./directives?id=declaring-directives

As a side note, I’m leaning toward HTTP headers (rather than query parameters) to send diagram options to a companion container:

https://github.com/yuzutech/kroki/blob/f953fcf117053ea00c47d45caec5bb3b5ad897d4/server/src/main/java/io/kroki/server/action/Delegator.java#L33-L37

Read more comments on GitHub >

github_iconTop Results From Across the Web

Replace foreignObject with standard SVG · Issue #2688 - GitHub
An SVG file generated by Mermaid cannot be edited using Inkscape (all boxes are ... MermaidJS: Suppress using HTML tags in SVG documents...
Read more >
html - Strange output when converting SVG to PDF javascript ...
Update 2: So I noticed that if I change the foreignObject's in the svg nodes to <text> elements and remove the div, I...
Read more >
SVG files created by Mermaid are displayed incorrectly - GitLab
Summary: An SVG exported by Mermaid live editor displays correctly in the browser, but using Inkscapes it's displayed all wrong.
Read more >
Mermaid Graphs and Flow Charts
It combines HTML and a form of Markdown with JavaScript to create SVG images of flows and other charts, which can be styled...
Read more >
Making Mermaid Diagrams in Markdown - CSS-Tricks
Using the same markup abstractions Markdown provides to notate code, Mermaid can be represented the same to output diagrams and flowcharts.
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