Compare commits

...

4 Commits

Author SHA1 Message Date
darshanr0107
c16d20c855 fix:prioritize flowchart.htmlLabels over global htmlLabels
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
2025-09-18 17:47:41 +05:30
darshanr0107
270f05d409 chore: add visual tests for html labels rendering
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
2025-09-18 15:01:40 +05:30
darshanr0107
c6134a05d2 chore: add changeset
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
2025-09-18 13:58:49 +05:30
darshanr0107
bf4a57fd04 fix: htmlLabels resolution for flowchart diagrams
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
2025-09-18 13:10:07 +05:30
5 changed files with 72 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
'mermaid': patch
---
fix: Ensure flowchart htmlLabels resolution respects both global and flowchart config

View File

@@ -1199,4 +1199,61 @@ class link myClass
`
);
});
describe('htmlLabels rendering', () => {
it('should not render with htmlLabels when disabled via flowchart config', () => {
imgSnapshotTest(
`flowchart LR
A["HTML label <br> with breaks"] --> B["Another label"]
C --> D
`,
{ flowchart: { htmlLabels: false } }
);
});
it('should not render with htmlLabels when disabled via global config', () => {
imgSnapshotTest(
`flowchart LR
A["HTML label <br> with breaks"] --> B["Another label"]
C --> D
`,
{ htmlLabels: false }
);
});
it('should render with htmlLabels when enabled', () => {
imgSnapshotTest(
`flowchart LR
A["HTML label <br> with breaks"] --> B["Another label"]
C --> D
`,
{ htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
);
});
it('should not render with htmlLabels when disabled via flowchart config, even when enabled in global config', () => {
imgSnapshotTest(
`flowchart LR
A["HTML label <br> with breaks"] --> B["Another label"]
C --> D
`,
{ htmlLabels: true, flowchart: { htmlLabels: false } },
undefined,
($svg) => {
expect($svg.find('foreignObject').length).to.equal(0);
}
);
});
it('should create foreignObject elements when htmlLabels enabled', () => {
renderGraph(
`flowchart TD
A["Node with <br> HTML"] -- "edge <br> label" --> B["Another node"]
C --> D
`,
{ htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
);
cy.get('svg foreignObject').should('exist');
});
});
});

View File

@@ -21,7 +21,13 @@ export const diagram = {
if (cnf.layout) {
setConfig({ layout: cnf.layout });
}
cnf.flowchart.htmlLabels = cnf.flowchart?.htmlLabels ?? cnf?.htmlLabels;
cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
setConfig({ flowchart: { arrowMarkerAbsolute: cnf.arrowMarkerAbsolute } });
setConfig({
flowchart: {
arrowMarkerAbsolute: cnf.arrowMarkerAbsolute,
htmlLabels: cnf.flowchart.htmlLabels,
},
});
},
};

View File

@@ -1,5 +1,4 @@
import { getConfig } from '../../diagram-api/diagramAPI.js';
import { evaluate } from '../../diagrams/common/common.js';
import { log } from '../../logger.js';
import { createText } from '../createText.js';
import utils from '../../utils.js';
@@ -45,8 +44,8 @@ export const getLabelStyles = (styleArray) => {
};
export const insertEdgeLabel = async (elem, edge) => {
let useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels);
const config = getConfig();
let useHtmlLabels = config.flowchart.htmlLabels;
const { labelStyles } = styles2String(edge);
edge.labelStyle = labelStyles;
const labelElement = await createText(elem, edge.label, {

View File

@@ -13,7 +13,7 @@ export const labelHelper = async <T extends SVGGraphicsElement>(
_classes?: string
) => {
let cssClasses;
const useHtmlLabels = node.useHtmlLabels || evaluate(getConfig()?.htmlLabels);
const useHtmlLabels = node.useHtmlLabels || evaluate(getConfig()?.flowchart?.htmlLabels);
if (!_classes) {
cssClasses = 'node default';
} else {