Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
8491523
fix: Add markdown-specific behavior on top of the common rendering ch…
darshanr0107 Dec 29, 2025
5a8ddd0
fix: streamline label creation in labelHelper function
darshanr0107 Jan 20, 2026
2cc90ef
fix: remove unused HTML label handling and streamline edge label crea…
darshanr0107 Jan 20, 2026
ef2e43d
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 20, 2026
50fa149
fix: simplify label creation in rect function by directly assigning t…
darshanr0107 Jan 20, 2026
970e5d8
Merge branch 'markdown-specific-changes' of https://github.com/mermai…
darshanr0107 Jan 20, 2026
287b94d
fix: update useHtmlLabels logic in labelHelper function
darshanr0107 Jan 21, 2026
99be550
fix: refactor label handling for markdown in clusters and edges
darshanr0107 Jan 22, 2026
f7de942
Revert "fix: refactor label handling for markdown in clusters and edges"
darshanr0107 Jan 22, 2026
649ee28
fix: set labelType to markdown for class relations
darshanr0107 Jan 24, 2026
931f3df
fix: set labelType to markdown for relationship edges
darshanr0107 Jan 24, 2026
a2587bc
fix: set labelType to markdown for requirement edges
darshanr0107 Jan 27, 2026
4893a9d
fix: update label type to markdown for state diagram edge labels
darshanr0107 Jan 27, 2026
443ff41
fix: update erBox to use getEffectiveHtmlLabels for label rendering
darshanr0107 Jan 27, 2026
5ac588a
Revert "fix: update erBox to use getEffectiveHtmlLabels for label ren…
darshanr0107 Jan 27, 2026
ab2d919
fix: enhance labelHelper to support markdown labels and improve label…
darshanr0107 Jan 27, 2026
a3841e8
fix: set labelType to markdown for note labels
darshanr0107 Jan 27, 2026
31abe0c
fix: update labelHelper to use logical OR for width calculation and s…
darshanr0107 Jan 27, 2026
63c2f6e
Merge branch 'develop' into markdown-specific-changes
darshanr0107 Jan 28, 2026
80de539
fix: update edge label handling by removing default width and improvi…
darshanr0107 Jan 28, 2026
cdfc346
Merge branch 'markdown-specific-changes' of https://github.com/mermai…
darshanr0107 Jan 28, 2026
1e06438
fix: append label element to edge label node for proper rendering
darshanr0107 Jan 28, 2026
2a045fa
fix: update insertEdgeLabel to pass the element to createText for mar…
darshanr0107 Jan 28, 2026
bc5382e
fix: update insertEdgeLabel to pass the element for label creation
darshanr0107 Jan 28, 2026
5f3b5a8
fix: enhance insertEdgeLabel to support markdown and adjust width han…
darshanr0107 Jan 28, 2026
25e1449
fix: wrap non-markdown text in paragraph tags for proper HTML formatting
darshanr0107 Jan 28, 2026
fa2f6c0
chore: update changeset
darshanr0107 Jan 29, 2026
904a589
fix: add nonMarkdownToHTML function for proper HTML conversion of non…
darshanr0107 Jan 29, 2026
43ca299
fix: specify labelType as markdown in insertEdges for block diagram
darshanr0107 Jan 29, 2026
9da5864
chore: add changeset for autoWrap in flowcharts
darshanr0107 Jan 29, 2026
7949762
fix: add isNode property to edge label configuration for block diagra…
darshanr0107 Jan 29, 2026
4e7d35f
fix: update label background color handling in block diagram
darshanr0107 Jan 30, 2026
5083b0c
fix: change label background color to transparent in block styles
darshanr0107 Jan 30, 2026
8d38c52
fix: update edge label background handling for markdown compatibility…
darshanr0107 Jan 30, 2026
0ee366e
fix: maintain backward compatibility for markdown label handling in e…
darshanr0107 Feb 3, 2026
8bd8039
Revert "fix: maintain backward compatibility for markdown label handl…
darshanr0107 Feb 3, 2026
deb4582
fix: simplify text content handling in addText function
darshanr0107 Feb 4, 2026
3b730a0
fix: enhance text handling in addText function for class diagrams
darshanr0107 Feb 4, 2026
8745456
fix: add labelType markdown for class diagram Nodes
darshanr0107 Feb 4, 2026
5438e9c
Revert "fix: add labelType markdown for class diagram Nodes"
darshanr0107 Feb 4, 2026
3c118d7
fix: revert changes in shapeUtil
darshanr0107 Feb 4, 2026
185ccf0
fix: remove labelType markdown from class diagram edges
darshanr0107 Feb 4, 2026
0d1d64e
Revert "fix: remove labelType markdown from class diagram edges"
darshanr0107 Feb 4, 2026
1f56f81
Merge branch 'develop' into markdown-specific-changes
darshanr0107 Feb 5, 2026
863808f
fix: set labelType to markdown for ER diagram node label
darshanr0107 Feb 6, 2026
144794b
fix: set labelType to markdown for class diagram notes
darshanr0107 Feb 6, 2026
1336d22
chore:update changeset on-behalf-of: @Mermaid-Chart <hello@mermaidcha…
darshanr0107 Feb 6, 2026
7732a23
chore:update changeset on-behalf-of: @Mermaid-Chart <hello@mermaidcha…
darshanr0107 Feb 6, 2026
fd3c1b0
Merge branch 'develop' into markdown-specific-changes
ashishjain0512 Feb 12, 2026
1384d58
fix: autowrapping in flowchart node labels
darshanr0107 Feb 12, 2026
1a18d30
fix: add space after html tag to non markdown text
darshanr0107 Feb 13, 2026
9ffe1cf
chore: update changeset
darshanr0107 Feb 16, 2026
10d2f77
fix: update handling of markdownAutoWrap to prevent text auto-wrappin…
darshanr0107 Feb 16, 2026
a11ca1f
fix: failing unit tests
darshanr0107 Feb 16, 2026
c46cb98
fix: autowrapping for edge labels
darshanr0107 Feb 16, 2026
9bbb075
fix: update edge label handling to respect markdownAutoWrap configura…
darshanr0107 Feb 16, 2026
40f9993
chore: add tests for auto wrapping of flowchart edge labels
darshanr0107 Feb 18, 2026
7d32db1
chore: update changeset
darshanr0107 Feb 18, 2026
c7f5850
revert changes to the markdownToLines - No auto wrapping unit tests
darshanr0107 Feb 19, 2026
fb6edef
Revert "fix: update edge label handling to respect markdownAutoWrap c…
darshanr0107 Feb 19, 2026
5d1e84f
fix: update nonMarkdownToLines to preserve spaces between HTML tags a…
darshanr0107 Feb 19, 2026
7517f83
fix: update tests for flowcharts edge label auto wrapping
darshanr0107 Feb 19, 2026
b8e7dec
chore:skip the markdownToLines - No auto wrapping test
darshanr0107 Feb 26, 2026
0476182
fix: ensure plain text edge labels are not treated as markdown
darshanr0107 Feb 26, 2026
ae60bc2
fix: refactor insertEdgeLabel to improve markdown label handling and …
darshanr0107 Feb 26, 2026
703995a
chore:update Edge label auto-wrapping tests and add nonMarkdownToLine…
darshanr0107 Feb 27, 2026
5b1dc43
chore:update edge label autowrapping tests
darshanr0107 Feb 27, 2026
dc7e7d8
Merge branch 'develop' into markdown-specific-changes
ashishjain0512 Feb 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/curvy-cases-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'mermaid': patch
---

fix: respect `markdownAutoWrap: false` to prevent text auto-wrapping in flowchart markdown labels with `htmlLabels` enabled.

Markdown labels with `markdownAutoWrap: false, htmlLabels: false` set doesn't work
correctly.
29 changes: 29 additions & 0 deletions .changeset/swift-cloths-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
'mermaid': patch
---

fix: Restore proper rendering of plain text flowchart labels without auto line-wrapping

This fix restores backwards compatibility with Mermaid v10 by ensuring that plain text labels in flowcharts are rendered correctly. In Mermaid v11, all labels were incorrectly being treated as markdown by default, which caused issues with text wrapping, multiline breaks, and backwards compatibility.

**What changed:**

- Plain text labels in flowcharts (without markdown syntax) now render as regular text
- For node labels and edge labels, these will line-wrap automatically. Although this isn't backwards compatible with v10, we think this is a minor change and it's worth keeping to avoid too many changes from diagrams created from v11 onwards.
- Plain text labels in other diagrams will continue to not line wrap.
- Plain text labels with `\n` characters now correctly create line breaks
- Plain text that looks like markdown (e.g., "1.", "- x") is no longer misinterpreted

**If you want markdown formatting:**
You can still use markdown in your flowchart labels by using the proper markdown syntax. Wrap your markdown text with double quotes and backticks:
``node["`_markdown_ **text**`"]``

Example:

````markdown
```mermaid
flowchart TD
plain["Plain text\nwith manual line break"]
markdown["`This is a **markdown** _label_ that wraps and doesn't replace \n with newlines`"]
```
````
32 changes: 30 additions & 2 deletions cypress/integration/rendering/flowchart-v2.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,8 @@ end
end
githost["Github, Gitlab, BitBucket, etc."]
githost2["\`Github, Gitlab, BitBucket, etc.\`"]
a["1."]
b["- x"]
a["\`1.\`"]
b["\`- x\`"]
`;

it('should render raw strings', () => {
Expand All @@ -1211,4 +1211,32 @@ class link myClass
`
);
});

describe('Edge label autowrapping', () => {
it('should wrap edge labels', () => {
imgSnapshotTest(
[
{
markdownAutoWrap: true,
htmlLabels: true,
},
{ markdownAutoWrap: true, htmlLabels: false },
{ markdownAutoWrap: false, htmlLabels: true },
// TODO: currently broken
// {markdownAutoWrap: false, htmlLabels: false},
].map(
({ markdownAutoWrap, htmlLabels }) => `---
config: ${JSON.stringify({ markdownAutoWrap, htmlLabels })}
title: Testing with ${JSON.stringify({ markdownAutoWrap, htmlLabels })}
---
flowchart TD
A["This is a really long line of plain text that will autowrap and support \\n newlines too."]
B["\`This is a really long line of **markdown** text that will autowrap, unless markdownAutoWrap:false is set.\`"]
A -- "Plain text **labels** in flowcharts will autowrap,like node labels. \\n Newline characters work too." --> B
B -- "\`**Markdown** edge labels will autowrap, unless markdownAutoWrap: false is set\`" --> C
`
)
);
});
});
});
45 changes: 45 additions & 0 deletions cypress/integration/rendering/flowchart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,3 +1004,48 @@ graph TD
);
});
});
it('#5824: should be able to render string and markdown labels', () => {
imgSnapshotTest(
`
flowchart TB
mermaid{"What is\nyourmermaid version?"} --> v10["<11"] --"\`<**1**1\`"--> fine["No bug"]
mermaid --> v11[">= v11"] -- ">= v11" --> broken["Affected by https://github.com/mermaid-js/mermaid/issues/5824"]
subgraph subgraph1["\`How to fix **fix**\`"]
broken --> B["B"]
end
githost["Github, Gitlab, BitBucket, etc."]
githost2["\`Github, Gitlab, BitBucket, etc.\`"]
a["1."]
b["- x"]
`,
{
flowchart: { htmlLabels: true },
securityLevel: 'loose',
}
);
});
it('69: should render subgraphs with adhoc list headings', () => {
imgSnapshotTest(
`
graph TB
subgraph "1. first"
a1-->a2
end
subgraph 2. second
b1-->b2
end
`,
{ fontFamily: 'courier' }
);
});
it('70: should render subgraphs with markdown headings', () => {
imgSnapshotTest(
`
graph TB
subgraph "\`**strong**\`"
a1-->a2
end
`,
{ fontFamily: 'courier' }
);
});
4 changes: 2 additions & 2 deletions docs/config/setup/mermaid/interfaces/ParseOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

# Interface: ParseOptions

Defined in: [packages/mermaid/src/types.ts:89](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L89)
Defined in: [packages/mermaid/src/types.ts:90](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L90)

## Properties

### suppressErrors?

> `optional` **suppressErrors**: `boolean`

Defined in: [packages/mermaid/src/types.ts:94](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L94)
Defined in: [packages/mermaid/src/types.ts:95](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L95)

If `true`, parse will return `false` instead of throwing error when the diagram is invalid.
The `parseError` function will not be called.
6 changes: 3 additions & 3 deletions docs/config/setup/mermaid/interfaces/ParseResult.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

# Interface: ParseResult

Defined in: [packages/mermaid/src/types.ts:97](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L97)
Defined in: [packages/mermaid/src/types.ts:98](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L98)

## Properties

### config

> **config**: [`MermaidConfig`](MermaidConfig.md)

Defined in: [packages/mermaid/src/types.ts:105](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L105)
Defined in: [packages/mermaid/src/types.ts:106](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L106)

The config passed as YAML frontmatter or directives

Expand All @@ -28,6 +28,6 @@ The config passed as YAML frontmatter or directives

> **diagramType**: `string`

Defined in: [packages/mermaid/src/types.ts:101](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L101)
Defined in: [packages/mermaid/src/types.ts:102](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L102)

The diagram type, e.g. 'flowchart', 'sequence', etc.
8 changes: 4 additions & 4 deletions docs/config/setup/mermaid/interfaces/RenderResult.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

# Interface: RenderResult

Defined in: [packages/mermaid/src/types.ts:115](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L115)
Defined in: [packages/mermaid/src/types.ts:116](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L116)

## Properties

### bindFunctions()?

> `optional` **bindFunctions**: (`element`) => `void`

Defined in: [packages/mermaid/src/types.ts:133](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L133)
Defined in: [packages/mermaid/src/types.ts:134](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L134)

Bind function to be called after the svg has been inserted into the DOM.
This is necessary for adding event listeners to the elements in the svg.
Expand All @@ -45,7 +45,7 @@ bindFunctions?.(div); // To call bindFunctions only if it's present.

> **diagramType**: `string`

Defined in: [packages/mermaid/src/types.ts:123](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L123)
Defined in: [packages/mermaid/src/types.ts:124](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L124)

The diagram type, e.g. 'flowchart', 'sequence', etc.

Expand All @@ -55,6 +55,6 @@ The diagram type, e.g. 'flowchart', 'sequence', etc.

> **svg**: `string`

Defined in: [packages/mermaid/src/types.ts:119](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L119)
Defined in: [packages/mermaid/src/types.ts:120](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L120)

The svg code for the rendered graph.
35 changes: 20 additions & 15 deletions packages/mermaid/src/dagre-wrapper/edges.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,32 @@ export const clear = () => {
export const insertEdgeLabel = async (elem, edge) => {
const config = getConfig();
const useHtmlLabels = getEffectiveHtmlLabels(config);
// Create the actual text element
const labelElement =
edge.labelType === 'markdown'
? // TODO: the createText function returns a `Promise`, so do we need an wait here?
createText(
elem,
edge.label,
{
style: edge.labelStyle,
useHtmlLabels,
addSvgBackground: true,
},
config
)
: await createLabel(elem, edge.label, edge.labelStyle);

// Create outer g, edgeLabel, this will be positioned after graph layout
const edgeLabel = elem.insert('g').attr('class', 'edgeLabel');

// Create inner g, label, this will be positioned now for centering the text
const label = edgeLabel.insert('g').attr('class', 'label');

// Create the actual text element
const isMarkdown = edge.labelType === 'markdown';
const labelElement = await createText(
elem,
edge.label,
{
style: edge.labelStyle,
useHtmlLabels,
// TODO: The old code only set addSvgBackground when using markdown, but
// this function is only used by block diagrams which never use markdown.
addSvgBackground: isMarkdown,
isNode: false,
markdown: isMarkdown,
// If using markdown, wrap using default width
width: isMarkdown ? undefined : Number.POSITIVE_INFINITY,
},
config
);

label.node().appendChild(labelElement);

// Center the label
Expand Down
14 changes: 12 additions & 2 deletions packages/mermaid/src/diagrams/block/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ const getStyles = (options: BlockChartStyleOptions) =>

.edgeLabel {
background-color: ${options.edgeLabelBackground};
/*
* This is for backward compatibility with existing code that didn't
* add a \`<p>\` around edge labels.
*
* TODO: We should probably remove this in a future release.
*/
p {
margin: 0;
padding: 0;
display: inline;
}
rect {
opacity: 0.5;
background-color: ${options.edgeLabelBackground};
Expand All @@ -101,8 +112,7 @@ const getStyles = (options: BlockChartStyleOptions) =>

/* For html labels only */
.labelBkg {
background-color: ${fade(options.edgeLabelBackground, 0.5)};
// background-color:
background-color: ${options.edgeLabelBackground};
}

.node .cluster {
Expand Down
2 changes: 2 additions & 0 deletions packages/mermaid/src/diagrams/class/classDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ export class ClassDB implements DiagramDB {
],
look: config.look,
parentId: note.parent,
labelType: 'markdown',
};
nodes.push(noteNode);

Expand Down Expand Up @@ -741,6 +742,7 @@ export class ClassDB implements DiagramDB {
style: classRelation.style || '',
pattern: classRelation.relation.lineType == 1 ? 'dashed' : 'solid',
look: config.look,
labelType: 'markdown',
};
edges.push(edge);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/mermaid/src/diagrams/er/erDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class ErDB implements DiagramDB {
look: getConfig().look ?? 'default',
cssClasses: 'default',
cssStyles: [],
labelType: 'markdown',
});
log.info('Added new entity :', name);
} else if (!this.entities.get(name)?.alias && alias) {
Expand Down Expand Up @@ -235,6 +236,7 @@ export class ErDB implements DiagramDB {
arrowTypeEnd: relationship.relSpec.cardA.toLowerCase(),
pattern: relationship.relSpec.relType == 'IDENTIFYING' ? 'solid' : 'dashed',
look: config.look,
labelType: 'markdown',
};
edges.push(edge);
}
Expand Down
1 change: 1 addition & 0 deletions packages/mermaid/src/diagrams/er/erTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface EntityNode {
cssClasses?: string;
cssStyles?: string[];
cssCompiledStyles?: string[];
labelType?: string;
}

export interface Attribute {
Expand Down
19 changes: 17 additions & 2 deletions packages/mermaid/src/diagrams/flowchart/flowDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ export class FlowDB implements DiagramDB {
return common.sanitizeText(txt, this.config);
}

private sanitizeNodeLabelType(labelType?: string) {
Comment thread
ashishjain0512 marked this conversation as resolved.
switch (labelType) {
case 'markdown':
case 'string':
case 'text':
return labelType;
default:
return 'markdown';
}
}

/**
* Function to lookup domId from id in the graph definition.
*
Expand Down Expand Up @@ -209,6 +220,7 @@ export class FlowDB implements DiagramDB {

if (doc?.label) {
vertex.text = doc?.label;
vertex.labelType = this.sanitizeNodeLabelType(doc?.labelType);
}
if (doc?.icon) {
vertex.icon = doc?.icon;
Expand Down Expand Up @@ -268,7 +280,7 @@ export class FlowDB implements DiagramDB {
if (edge.text.startsWith('"') && edge.text.endsWith('"')) {
edge.text = edge.text.substring(1, edge.text.length - 1);
}
edge.labelType = linkTextObj.type;
edge.labelType = this.sanitizeNodeLabelType(linkTextObj.type);
}

if (type !== undefined) {
Expand Down Expand Up @@ -695,7 +707,7 @@ You have to call mermaid.initialize.`
title: title.trim(),
classes: [],
dir,
labelType: _title.type,
labelType: this.sanitizeNodeLabelType(_title?.type),
};

log.info('Adding', subGraph.id, subGraph.nodes, subGraph.dir);
Expand Down Expand Up @@ -1005,6 +1017,7 @@ You have to call mermaid.initialize.`
const baseNode = {
id: vertex.id,
label: vertex.text,
labelType: vertex.labelType,
labelStyle: '',
parentId,
padding: config.flowchart?.padding || 8,
Expand Down Expand Up @@ -1081,6 +1094,7 @@ You have to call mermaid.initialize.`
id: subGraph.id,
label: subGraph.title,
labelStyle: '',
labelType: subGraph.labelType,
parentId: parentDB.get(subGraph.id),
padding: 8,
cssCompiledStyles: this.getCompiledStyles(subGraph.classes),
Expand Down Expand Up @@ -1112,6 +1126,7 @@ You have to call mermaid.initialize.`
end: rawEdge.end,
type: rawEdge.type ?? 'normal',
label: rawEdge.text,
labelType: rawEdge.labelType,
labelpos: 'c',
thickness: rawEdge.stroke,
minlen: rawEdge.length,
Expand Down
Loading
Loading