Skip to content

\n in node labels rendered literally instead of as a newline #376

Description

@mikejhill

Environment

  • Extension: Markdown Preview Mermaid Support v1.32.0
  • VS Code: 1.112.0

Description

\n sequences in node labels are rendered as text rather than line breaks.

It seems this is a regression introduced in Mermaid v11.0.0. It worked correctly in Mermaid 10.9.3. See mermaid-js/mermaid#6048.

Interestingly, mermaid.live renders \n correctly for the same diagram. It's not clear to me whether they're preprocessing the text or using different renderer logic.

Example

```mermaid
graph TB
    A["Line one\nLine two"]
    B["GCP Origin\n(single region)"]
```
Actual (Markdown Preview Extension)
Image
Expected (GitHub)
graph TB
    A["Line one\nLine two"]
    B["GCP Origin\n(single region)"]
Loading

Workaround

Replacing \n with <br> works. I can actually only find <br> in the docs (link), but it seems many renderers support \n, including mermaid.live, GitHub's GFM, and (until its own regression) Mermaid.js itself.


I assume this could just be addressed by the upstream fix after it is available. However, given the original issue is 1.5 years old and only recently got a response, it may be helpful to have an interim fix to cover the gap, such as preprocessing \n in quoted labels to replace with <br>. This would resolve a lot of the confusion we're seeing with Markdown authored in other sources today, particularly as Markdown is becoming increasingly popular and important with the trend in documentation-centric approaches.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions