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

Render diagrams using non-browser-based rendering libraries #2485

Open
ghost opened this issue Nov 14, 2021 · 12 comments
Open

Render diagrams using non-browser-based rendering libraries #2485

ghost opened this issue Nov 14, 2021 · 12 comments
Labels
Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Nov 14, 2021

The following diagram renders fine in Firefox:

The diagram does not render correctly using the following programs and libraries:

Many applications rely on those libraries for rendering SVG diagrams. For example, my text editor KeenWrite uses Kroki to generate mermaid SVG documents. These documents are then parsed by EchoSVG to render as PNG images in FlyingSaucer.

In the following image, the rendered SVG output is shown at the right:

keenwrite

Other SVG producers, such as Graphviz, can generate SVG documents that can be rendered using the aforementioned libraries. See KeenWrite's screenshots for example image renders that use Kroki. The mermaid diagrams cannot be fully rendered.

Feature request: Have mermaid generate simpler CSS/SVG by default that can be parsed and rendered by the majority of those libraries.

@ghost ghost added Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request labels Nov 14, 2021
@ghost ghost changed the title Diagrams using non-browser-based rendering libraries Render diagrams using non-browser-based rendering libraries Nov 14, 2021
@jgreywolf
Copy link
Contributor

@DaveJarvis you mention MS Word - since word does not support adding SVG into documents, I am curious how you were able to verify this...

Mermaid Chart is working with MS to publish a plug in for Word, PowerPoint and OneNote that will allow users to insert diagrams from their mermaid chart library directly. Due to limitations in the Office model SVG is not supported, so we are rendering to PNG before insert.

Actually - now that I think about it, in PowerPoint you can insert an SVG, but I think it converts to PNG during the process (and as you have mentioned above, is not rendered correctly)

@jgreywolf
Copy link
Contributor

Assigning to myself to review

@jgreywolf jgreywolf self-assigned this Aug 28, 2023
@ghost
Copy link
Author

ghost commented Aug 28, 2023

@jgreywolf

Due to limitations in the Office model SVG is not supported, so we are rendering to PNG before insert.

That's unfortunate. An SVG format is usually selected because it doesn't lose resolution when scaled. Using PNG images only (partially) solves the problem of embedding into MS documents and still leaves at least 13 other libraries (and countless dependent applications) unable to render MermaidJS diagrams.

Is solving the deeper problem of having MermaidJS produce SVG-compliant output not feasible?

@jgreywolf
Copy link
Contributor

I was just asking in regards to the MS Word part.
I am investigating the SVG-compliant aspect

@taylorh140
Copy link

I’m curious what actions need to be taken in moving this forward. Does this imply adding something like svgdom into the mermaid library, removing the variance in browser layout engines?

@taylorh140
Copy link

I was just asking in regards to the MS Word part.
I am investigating the SVG-compliant aspect

Also I thought word recently added svg support. I’ll have to check again.

@ghost
Copy link
Author

ghost commented Aug 31, 2023

Also I thought word recently added svg support. I’ll have to check again.

https://office-watch.com/2016/svg-graphics-coming-to-office-at-long-last/

@ghost
Copy link
Author

ghost commented Oct 5, 2023

FYI, in two days I will be locked out of my account once GitHub begins enforcing MFA. Sorry I won't be able to help any further.

@willcl-ark
Copy link

I am hitting this issue using prawn-svg. Has there been any update on not using foreignObject (embedded HTML) in mermaid diagrams?

willcl-ark added a commit to willcl-ark/onboarding-to-bitcoin-core that referenced this issue Nov 30, 2023
prawn-svg cannot render SVG fropm mermaid, see
mermaid-js/mermaid#2485 (comment)

For more info.
willcl-ark added a commit to willcl-ark/onboarding-to-bitcoin-core that referenced this issue Nov 30, 2023
prawn-svg cannot render SVG fropm mermaid, see
mermaid-js/mermaid#2485 (comment)

For more info.
willcl-ark added a commit to willcl-ark/onboarding-to-bitcoin-core that referenced this issue Nov 30, 2023
prawn-svg cannot render SVG fropm mermaid, see
mermaid-js/mermaid#2485 (comment)

For more info.
@earonesty
Copy link

earonesty commented Jan 27, 2024

years later... it still doesn't render in most things besides browsers. pie charts work. i can clean up the svg manually and get it to work. might see about making a pr, so mermaid generates "easier" svg.

@geffen
Copy link

geffen commented Apr 14, 2024

Just ran into this trying to take SVGs into anything Adobe - Photoshop, Indesign, etc... Corrupt file from their POV.
2024-04-14 00_32_31-Adobe Photoshop

@carlosame
Copy link

carlosame commented Jul 28, 2024

Out there, people keep posting a "list of libraries that cannot render Mermaid files" taken from this issue, which includes the EchoSVG project that I manage. And although EchoSVG's Mermaid renderings aren't perfect, it is able to render many Mermaid diagrams since 2022 (after the OP of this issue asked for it).

You need to use the CSSTranscodingHelper which supports custom properties and other modern CSS.

Some examples from the EchoSVG test suite (the SVG was taken from Mermaid's website) follow:

Mermaid class diagram rendered by EchoSVG

Mermaid mindmap diagram rendered by EchoSVG

Mermaid E-R diagram rendered by EchoSVG

Mermaid sequence background diagram rendered by EchoSVG

Mermaid sankey diagram rendered by EchoSVG

However it often omits the text that overflows, yet that bug has little to do with foreignObject AFAIK:

Mermaid flowchart diagram rendered by EchoSVG

So the output is far from perfect, but better than it used to be (and preferable to the "black squares" that I hear about).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants