mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 00:40:22 +02:00
Compare commits
4 Commits
mermaid@11
...
fix/flowch
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c16d20c855 | ||
![]() |
270f05d409 | ||
![]() |
c6134a05d2 | ||
![]() |
bf4a57fd04 |
5
.changeset/lazy-wolves-film.md
Normal file
5
.changeset/lazy-wolves-film.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'mermaid': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: Ensure flowchart htmlLabels resolution respects both global and flowchart config
|
@@ -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');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -21,7 +21,13 @@ export const diagram = {
|
|||||||
if (cnf.layout) {
|
if (cnf.layout) {
|
||||||
setConfig({ layout: cnf.layout });
|
setConfig({ layout: cnf.layout });
|
||||||
}
|
}
|
||||||
|
cnf.flowchart.htmlLabels = cnf.flowchart?.htmlLabels ?? cnf?.htmlLabels;
|
||||||
cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
|
cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
|
||||||
setConfig({ flowchart: { arrowMarkerAbsolute: cnf.arrowMarkerAbsolute } });
|
setConfig({
|
||||||
|
flowchart: {
|
||||||
|
arrowMarkerAbsolute: cnf.arrowMarkerAbsolute,
|
||||||
|
htmlLabels: cnf.flowchart.htmlLabels,
|
||||||
|
},
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
||||||
import { evaluate } from '../../diagrams/common/common.js';
|
|
||||||
import { log } from '../../logger.js';
|
import { log } from '../../logger.js';
|
||||||
import { createText } from '../createText.js';
|
import { createText } from '../createText.js';
|
||||||
import utils from '../../utils.js';
|
import utils from '../../utils.js';
|
||||||
@@ -45,8 +44,8 @@ export const getLabelStyles = (styleArray) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const insertEdgeLabel = async (elem, edge) => {
|
export const insertEdgeLabel = async (elem, edge) => {
|
||||||
let useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels);
|
const config = getConfig();
|
||||||
|
let useHtmlLabels = config.flowchart.htmlLabels;
|
||||||
const { labelStyles } = styles2String(edge);
|
const { labelStyles } = styles2String(edge);
|
||||||
edge.labelStyle = labelStyles;
|
edge.labelStyle = labelStyles;
|
||||||
const labelElement = await createText(elem, edge.label, {
|
const labelElement = await createText(elem, edge.label, {
|
||||||
|
@@ -13,7 +13,7 @@ export const labelHelper = async <T extends SVGGraphicsElement>(
|
|||||||
_classes?: string
|
_classes?: string
|
||||||
) => {
|
) => {
|
||||||
let cssClasses;
|
let cssClasses;
|
||||||
const useHtmlLabels = node.useHtmlLabels || evaluate(getConfig()?.htmlLabels);
|
const useHtmlLabels = node.useHtmlLabels || evaluate(getConfig()?.flowchart?.htmlLabels);
|
||||||
if (!_classes) {
|
if (!_classes) {
|
||||||
cssClasses = 'node default';
|
cssClasses = 'node default';
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user