12

Is there a way to set a max width for text within a Mermaid flowchart node, such that it automatically wraps?

For example - how would I get the first graph to look like the second graph, without painstakingly inserting manual line breaks:

<script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.14.0/mermaid.min.js"></script>

<div class="mermaid">
flowchart TD
    A{Is it Friday midday UTC?} -- Yes --> B(Check out Daft Punk's new single 'Get Lucky' if you have the chance. Sound of the summer.)
    A -- No --> C(Never mind then)
</div>

<h2>Desired output</h2>
<div class="mermaid">
flowchart TD
    A{Is it Friday</br>midday UTC?} -- Yes --> B(Check out Daft Punk's new single</br>'Get Lucky' if you have the chance.</br>Sound of the summer.)
    A -- No --> C(Never mind then)
</div>

Screenshot of results

I have a suspicion the solution will be a single line of CSS but I don't know what it is.

Jack Deeth
  • 3,062
  • 3
  • 24
  • 39
  • 4
    [Flowchart ability to Wrap text when text in flowchart is too long · Issue #1321 · mermaid-js/mermaid](https://github.com/mermaid-js/mermaid/issues/1321 "Flowchart ability to Wrap text when text in flowchart is too long · Issue #1321 · mermaid-js/mermaid") – Ooker Aug 11 '22 at 09:04

1 Answers1

4

There is support for wrapping of text in Mermaid now: https://www.mermaidchart.com/blog/posts/automatic-text-wrapping-in-flowcharts-is-here

In short, a new string format was introduced in version 10.1.0 of Mermaid allowing markdown formatting and wrapping of lines. The format currently works in flowcharts and mind maps. To create such a string start with "` and close the string with `". If you do a new line in this kind of string, the text will be rendered as such in the diagram.

Sample diagram using this kind of strings:

mindmap
    id1("`**Root**`"]
      id2["`A formatted text... with **bold** and *italics*`"]
      id3[Regular labels works as usual]
      id4["`Emojis and Unicode works too: 
      शान्तिः سلام  和平 `"]
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34196024) – InSync Apr 16 '23 at 07:42