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

Line breaks are rendered as <br> and not <br/> in the resulting svg file, resulting in parsing errors for external svg parsers #1766

Open
frederikfab opened this issue Nov 11, 2020 · 8 comments
Labels
Graph: Timeline Internals: Parser Status: Pending Is not to be executed as it currently is Type: Bug / Error Something isn't working or is incorrect

Comments

@frederikfab
Copy link

frederikfab commented Nov 11, 2020

Describe the bug
Line breaks are rendered as <br> and not <br/> in the resulting svg file, resulting in parsing errors for external svg parsers

To Reproduce
Render the diagram

graph TD
    F[Line break `<br/>` Line 2] --> R
Loading

<br/> gets rendered as <br>

Expected behavior
<br/> and <br> and <br /> should get rendered as <br/> to be valid xml and parse correctly in more parsers.

@frederikfab frederikfab added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Nov 11, 2020
@knsv knsv added Status: Approved Is ready to be worked on Good first issue! and removed Status: Triage Needs to be verified, categorized, etc labels Nov 12, 2020
@knsv
Copy link
Collaborator

knsv commented Nov 12, 2020

What a silly problem. We must fix this.

@knsv knsv added this to the 8.9.0 milestone Nov 26, 2020
@ashishjain0512
Copy link
Collaborator

ashishjain0512 commented Nov 26, 2020

@frederikfab The issue is when we parse and prepare to render the SVG, it has the proper <br/> closing tag, but in the case when the setting is htmlLabel =true, then, we rely on the native SVG.innerHTML() to render/draw it, and that gives back only <br>.

For your case I would recommend you try using the setting htmlLabel=false, then you should get the desired result, as here we have better control over how we break the label even before we style it, instead of depending on HTML rendering by the browser.

Let us know if this fixes your issue.

@frederikfab
Copy link
Author

I have tried to set this option, but it does not seem to make a difference. I think i might be doing it wrong though:

%%{init: {'htmlLabel': false}%%

graph LR
%%{config: {'htmlLabel': false}%%

    A --> B[Line 1 <br/>Line 2]

@frederikfab
Copy link
Author

also tried adding an s to htmlLabels above, made no difference.

In my workflow, I am using the markdown mermaid extension in vscode, so I do not control how the mermaid library is initialized - I understand if you see that as a requirement for addressing this, though.

@titibandit
Copy link

rendering my graph

graph TB
    F{the line <br/> after breaking} --> R

using

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

as a config file works! Line breaks are now rendered.
I use mermaid-cli to generate my chart, and view the resulting SVGs in Firefox.

@jgreywolf
Copy link
Contributor

@frederikfab
Is this still an issue for you in VSCode? The issue may need to be reviewed by the team that manages that add in

@jgreywolf jgreywolf added Close after 30 days Close issue if no response after 30 days Status: Pending Is not to be executed as it currently is and removed Status: In progress Status: Approved Is ready to be worked on labels Jan 26, 2023
@AkechiShiro
Copy link

AkechiShiro commented Jun 5, 2023

It may still be an issue, or I'm definitely facing a different one, <br> in a timeline diagram shows as </br> and there is no line break inserted in my SVG files.
But this issue is reproducible for png files as well.

timeline
    Section XXX
    XXX : XXX<br>YYY 

Shows up as
image

I'm using version : 10.1.0 with npx -p @mermaid-js/mermaid-cli mmdc -i

If it is believed to be another issue, I'll open a new one and delete this comment here (to avoid pollution with non-issue related comment here).

Note
This does not happen in the live editor but the live editor's version is not 10.1.0, it is v10.2.2

@jandrieu
Copy link

This error is because SVG is expected to be XML. The use of
within a is invalid HTML

Currently, this mermaid

flowchart TD
  F(Finance) --- F.1["F.1 Reuse Know
  your customer"]

generates this image:

    flowchart TD
  F(Finance) --- F.1["F.1 Reuse Know
  your customer"]
Loading

which has this html

 <span class="nodeLabel"><p>F.1 Reuse Know<br>your customer</p></span>

That <br> is an XML error. Any self-respecting SVG parser should throw an error.

It should be <br/>

FWIW, we are trying to use mermaid in specifications at the W3C and their new tooling requires strict parsing of SVGs. So this is a gating factor to continue to use mermaid. =(

It looks like this should have been fixed in jupyterlab/jupyterlab#15661 but as pointed out in jupyterlab/jupyterlab#15661 (comment) the PR doesn't solve the problem with newlines in the mermaid, as illustrated above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Graph: Timeline Internals: Parser Status: Pending Is not to be executed as it currently is Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants