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

How to add newline in the text #384

Closed
coolgoose85 opened this issue Aug 31, 2016 · 30 comments · Fixed by #764
Closed

How to add newline in the text #384

coolgoose85 opened this issue Aug 31, 2016 · 30 comments · Fixed by #764

Comments

@coolgoose85
Copy link

I am trying to break the text in two lines on top of arrows or on notes but newline is not working anywhere

Example
Note right of ABC: - Group all \n large and medium

OR

abc->>cuz: How are \n you?

Am I missing some syntax?

@coolgoose85 coolgoose85 changed the title How to add newline in the comments How to add newline in the text Aug 31, 2016
@jboelter
Copy link

jboelter commented Oct 6, 2016

Doesn't look like this is currently supported. For example, with sequence diagrams the drawNote is correctly provided a multi-line input, but is putting it directly into an svg field. There's some commented code in drawSvg that might be a starting point for a contribution.

@knsv
Copy link
Collaborator

knsv commented Oct 7, 2016

We should support this. A good task for someone that wants to be a part of the project.

@alanmimms
Copy link

One of the examples for sequence diagrams shows HTML <br/>, and it happens that the sample breaks the line at that point. But if you add another <br/> or move the existing one the line break doesn't follow it. Apparently that is simply ignored.

@Naishy
Copy link

Naishy commented Feb 21, 2017

I found that using <br/> in node text gives line breaks as expected, including for multiple breaks if required. Tested on Chromium 55.0.2883.87 and Firefox 51.0.1

@ufo2mstar
Copy link

Sorry, still not giving line breaks as expected for sequence diagrams (Chrome 56+ and Firefox 51+).
I will try to work on this feature soon.

@scordature
Copy link

Line breaks work in graph diagrams, except not in Subgraph names.
They do not work in sequence diagrams, at all.

graph TD;

subgraph Line breaks <br /> don't work in <br /> Subgraphs
    inset[Line breaks <br />work in <br />Insets]
end

    inset-->A

  A(Line breaks<br />work in<br />rounded rec nodes)
  B{Line breaks <br />work in<br />decision nodes}
  C[Line breaks<br />work in<br /> rectangles]
  D((Line breaks <br />work in <br />circles))
  E>Line breaks <br />work in <br />flag nodes]


    A-->B
    B--yes-->C
    B--no-->E
    C-->D
 


style A fill:#ed6,stroke:#333,stroke-width:2px;
style B fill:#ed6,stroke:#333,stroke-width:2px;
style C fill:#ed6,stroke:#333,stroke-width:2px;
style D fill:#ed6,stroke:#333,stroke-width:2px;
style E fill:#ed6,stroke:#333,stroke-width:2px;
style inset fill:#ed6,stroke:#333,stroke-width:2px;

@Lucas-C
Copy link

Lucas-C commented Sep 18, 2017

<br> is not fully supported: the following graph generates an "Opening and ending tag mismatch: br line 0 and div" error, both with mmdc and in mermaid-live-editor:

graph TD
B(B<br>b)

@tylerlong
Copy link
Collaborator

@Lucas-C
Copy link

Lucas-C commented Sep 19, 2017

Yeah, I wasn't clear about this one: click "Download SVG" and you'll see the error

@tylerlong
Copy link
Collaborator

tylerlong commented Sep 20, 2017

@Lucas-C Confirmed. Downloaded SVG doesn't work.
I am not a SVG format expert. Maybe <br> is invalid in SVG. More investigation is needed.

@alanmimms
Copy link

At least some SVG implementations support newline, but not using HTML's <br/> tag. This sort of question gets asked a lot.

Instead, SVG evidently supports embedding the ASCII NL character. An example is here.

@Lucas-C
Copy link

Lucas-C commented Sep 25, 2017

So a fix could be to replace every <br> by a \n ?

@alanmimms
Copy link

I suspect the fix would be to replace the <br> tags with &#xA; as described in the example I pointed to above.

@katherinermartin
Copy link

katherinermartin commented Sep 28, 2017

@alanmimms @Lucas-C I'm unable to get &#xA; to work in mermaid-live-editor (I think because of the semi colon, and I haven't figured out a way to escape it out as a special character).
To continue with Lucas' code and per Alan's linked example, this is what I've input to the editor:

graph TD
B(B &#xA; b)

Any suggestions?

@DorfilIkatu
Copy link

DorfilIkatu commented Oct 10, 2017

@KaptainRose write different lines between <p> and </p>... it worked for me

@katherinermartin
Copy link

@DorfilIkatu thank you so much, it worked!

@galaxy001
Copy link

Please make it to output <br/> as it is, instead of changing it to <br> and break Firefox XML parser.

@oisu
Copy link

oisu commented Feb 16, 2018

I tried using <p></p>, it works but makes additional line space.
<div></div> instead perfectly works for me 🙂

@tylerlong
Copy link
Collaborator

tylerlong commented Mar 16, 2018

@galaxy001

Please make it to output <br/> as it is, instead of changing it to <br> and break Firefox XML parser.

done

@Lucas-C

So a fix could be to replace every <br> by a \n ?

<br/> works

@jhvanderven
Copy link

Will this be supported in the sequence diagram too?

@BHunter2889
Copy link

BHunter2889 commented Oct 1, 2018

@galaxy001

Please make it to output <br/> as it is, instead of changing it to <br> and break Firefox XML parser.
@tylerlong
done

This doesn't appear to be done. At least not in the Live Editor. I had to go into the svg and manually change all to be <br/>, which worked.

watsoncj added a commit to watsoncj/mermaid that referenced this issue Nov 26, 2018
- Add support for <br/> delimiter in actor descriptions.
- Add actorFontFamily and actorFontSize options to sequence diagram.
- Change default actor description font from times to sans.

Fix mermaid-js#384 mermaid-js#702 mermaid-js#755
@jayagopaldaz
Copy link

jayagopaldaz commented Apr 14, 2019

i think there's still some work to be done here. should i try to become a collaborator?:

graph TD

Y(BEHAVIOUR OUTSIDE<br/>OF SUBGRAPHS)
Z(BEHAVIOUR OUTSIDE<br>OF SUBGRAPHS)
a-- long arrow message line 1<br>line 2 of long arrow message --> b
c-- long arrow message line 1<br/>line 2 of long arrow message --> d

subgraph BEHAVIOUR INSIDE<br>OF SUBGRAPHS
  e-- long arrow message line 1<br>line 2 of long arrow message --> f
end

subgraph BEHAVIOUR INSIDE<br/>OF SUBGRAPHS
  g-- long arrow message line 1<br/>line 2 of long arro- message --> h
end

see the mermaid-live-editor view here

in gitlab, none of these examples introduce newlines.

@skorokithakis
Copy link

I cannot get the live-editor to introduce newlines in any browser with any method as well. Please reopen this.

@Tinkerer-
Copy link

I tried to get a newline in a box in Pandoc, with Mardown Preview Enhanced, and also did not manage to get a newline. Would be greatly appreciated if this could be fixed.

@rajasekaran2003
Copy link

Sorry, still not giving line breaks as expected for sequence diagrams (Chrome 56+ and Firefox 51+).
I will try to work on this feature soon.

any progress on this?

sequence diagrams still doesn't support multi lines for message lines,

@rajasekaran2003
Copy link

rajasekaran2003 commented Jun 18, 2019 via email

@gakonst
Copy link

gakonst commented Jun 28, 2019

+1, I'd like to get multiline text in a Sequence Diagram, no clear way to do this still. Can this be reopened?

@nicola
Copy link

nicola commented Jul 2, 2019

same here!

@etimau
Copy link

etimau commented Dec 3, 2019

When using
in a sequenceDiagram, when exported to SVG it is translated to tags.
See this example

Is it possible to have the same behavior in flowcharts?
If you try this and click on "Download SVG", the result has a parse XML error because of the
tag.
Idem if the
is inside a node.

@IOrlandoni
Copy link
Member

@etimau Hey! You're commenting in an old closed issue. Feel free to create a new issue if you found a bug, need help, want to request a feature or anything!

@mermaid-js mermaid-js locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.