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
10 changed files with 116 additions and 90 deletions

View File

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

View File

@@ -1,5 +0,0 @@
---
'mermaid': patch
---
fix: Resolve gantt chart crash due to invalid array length

View File

@@ -58,7 +58,7 @@ jobs:
echo "EOF" >> $GITHUB_OUTPUT
- name: Commit and create pull request
uses: peter-evans/create-pull-request@915d841dae6a4f191bb78faf61a257411d7be4d2
uses: peter-evans/create-pull-request@18e469570b1cf0dfc11d60ec121099f8ff3e617a
with:
add-paths: |
cypress/timings.json

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

@@ -803,34 +803,4 @@ describe('Gantt diagram', () => {
{}
);
});
it('should handle numeric timestamps with dateFormat x', () => {
imgSnapshotTest(
`
gantt
title Process time profile (ms)
dateFormat x
axisFormat %L
tickInterval 250millisecond
section Pipeline
Parse JSON p1: 000, 120
`,
{}
);
});
it('should handle numeric timestamps with dateFormat X', () => {
imgSnapshotTest(
`
gantt
title Process time profile (ms)
dateFormat X
axisFormat %L
tickInterval 250millisecond
section Pipeline
Parse JSON p1: 000, 120
`,
{}
);
});
});

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

@@ -268,9 +268,7 @@ const fixTaskDates = function (startTime, endTime, dateFormat, excludes, include
const getStartDate = function (prevTime, dateFormat, str) {
str = str.trim();
if ((dateFormat.trim() === 'x' || dateFormat.trim() === 'X') && /^\d+$/.test(str)) {
return new Date(Number(str));
}
// Test for after
const afterRePattern = /^after\s+(?<ids>[\d\w- ]+)/;
const afterStatement = afterRePattern.exec(str);

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 {

88
pnpm-lock.yaml generated
View File

@@ -18,7 +18,7 @@ importers:
version: 3.50.2(encoding@0.1.13)(typescript@5.7.3)
'@argos-ci/cypress':
specifier: ^5.0.2
version: 5.0.7(cypress@14.5.1)
version: 5.0.2(cypress@14.5.1)
'@changesets/changelog-github':
specifier: ^0.5.1
version: 0.5.1(encoding@0.1.13)
@@ -30,7 +30,7 @@ importers:
version: 8.19.4(eslint@9.26.0(jiti@2.4.2))
'@cypress/code-coverage':
specifier: ^3.12.49
version: 3.13.4(@babel/core@7.27.1)(@babel/preset-env@7.28.3(@babel/core@7.27.1))(babel-loader@9.2.1(@babel/core@7.27.1)(webpack@5.95.0(esbuild@0.25.0)))(cypress@14.5.1)(webpack@5.95.0(esbuild@0.25.0))
version: 3.13.4(@babel/core@7.27.1)(@babel/preset-env@7.27.2(@babel/core@7.27.1))(babel-loader@9.2.1(@babel/core@7.27.1)(webpack@5.95.0(esbuild@0.25.0)))(cypress@14.5.1)(webpack@5.95.0(esbuild@0.25.0))
'@eslint/js':
specifier: ^9.26.0
version: 9.26.0
@@ -795,26 +795,26 @@ packages:
resolution: {integrity: sha512-4YQc/FGYmA4Jx8vRNRI6YOE8oa7tOWhCik3b1OV3RQ6OkAY5EpVRF8ruiFpX+9BIjZ2V5AdVpsJacYOIiCHNMg==}
engines: {node: '>=12.13.0'}
'@argos-ci/api-client@0.8.2':
resolution: {integrity: sha512-+b0qq5SSrLcI3NvUdNxsTSb8UkRPF2q8jJKlSHUJEyuMktIliWS2yuzLZYnbjTs7Zw654oRpc15cePwVcCG5jg==}
'@argos-ci/api-client@0.8.1':
resolution: {integrity: sha512-3IHv7ANSPNO6OwWgwULlHbP9/tFV9kQDu6+nL9jysfPkGj0GgtrOsyBb+iU931c7wSMo1OD+XNujCnRzDD968w==}
engines: {node: '>=18.0.0'}
'@argos-ci/browser@4.2.1':
resolution: {integrity: sha512-10BxuF4L31AGZG1UX44QHRwpNoAZbW/4OpsF5VtoGB0vduwSgRbRljz33vWgDuN3ylEP7zKUa6J56YwvA1VaFA==}
'@argos-ci/browser@4.1.2':
resolution: {integrity: sha512-OljPFzxSNndWSwMBxKGtN3p8lSbt73z+/0CIXbBVTQOPjPMErXWjgtrFL23xqtTq5wdds3uxGv7tjVDWJbgBYg==}
engines: {node: '>=18.0.0'}
'@argos-ci/core@3.2.3':
resolution: {integrity: sha512-5xr7h4PsQntAb5KJ6U+QnI5pcEEfHei3pclb0rCUM4Qzg1aTJMSvntlrjCCC89BQqfhz8PlxkrPlA8zJktNvaw==}
'@argos-ci/core@3.2.1':
resolution: {integrity: sha512-P+tGofNLAtH0+e87M8sZc+juAtbOcnV6z2nA2MwB2OzUVVXGINJHAF2cK0ZUyXC9d8a7RL0+rQWkP4vXDA/gBw==}
engines: {node: '>=18.0.0'}
'@argos-ci/cypress@5.0.7':
resolution: {integrity: sha512-2rJyfo30ff98UZKi1dXZEWbPcE6sgO9o8ypAQcX8MFaQyO1xOzDBgQ73n8LKtmbqJ/+6E5alFbpa6cnaN1QWwQ==}
'@argos-ci/cypress@5.0.2':
resolution: {integrity: sha512-k3h4qZohLh5BM0oVH3S8RcV8xw4ssTpG6/svm/wjucoE4auqfDTrkkPjnuxmbY6qB74V/JWcZIEV0DU6haMhFg==}
engines: {node: '>=18.0.0'}
peerDependencies:
cypress: ^12.0.0 || ^13.0.0 || ^14.0.0
'@argos-ci/util@2.3.3':
resolution: {integrity: sha512-XgpHGGgj3QAGXWwiM4aOP61AzFT1KfLXExbUoCzsj8VXCe8FjqnuFojefbsiQUWWmDx6LoYZYIvoN6xKuTFCeA==}
'@argos-ci/util@2.3.2':
resolution: {integrity: sha512-xtNHJxpWYNst/sMNn4Jv/vkODuFsJ+APr4FBeoFUdIa+Izjl4ZFHsYA2PUyu+ygIpQCkof8yZLL9U1/VpiyyIw==}
engines: {node: '>=18.0.0'}
'@asamuzakjp/css-color@2.8.3':
@@ -1438,6 +1438,12 @@ packages:
peerDependencies:
'@babel/core': ^7.0.0
'@babel/preset-env@7.27.2':
resolution: {integrity: sha512-Ma4zSuYSlGNRlCLO+EAzLnCmJK2vdstgv+n7aUP+/IKZrOfWHOJVdSJtuub8RzHTj3ahD37k5OKJWvzf16TQyQ==}
engines: {node: '>=6.9.0'}
peerDependencies:
'@babel/core': ^7.0.0-0
'@babel/preset-env@7.28.3':
resolution: {integrity: sha512-ROiDcM+GbYVPYBOeCR6uBXKkQpBExLl8k9HO1ygXEyds39j+vCCsjmj7S8GOniZQlEs81QlkdJZe76IpLSiqpg==}
engines: {node: '>=6.9.0'}
@@ -4412,6 +4418,11 @@ packages:
peerDependencies:
'@babel/core': ^7.4.0 || ^8.0.0-0 <8.0.0
babel-plugin-polyfill-corejs3@0.11.1:
resolution: {integrity: sha512-yGCqvBT4rwMczo28xkH/noxJ6MZ4nJfkVYdoDaC/utLtWrXxv27HVrzAeSbqR8SxDsp46n0YF47EbHoixy6rXQ==}
peerDependencies:
'@babel/core': ^7.4.0 || ^8.0.0-0 <8.0.0
babel-plugin-polyfill-corejs3@0.13.0:
resolution: {integrity: sha512-U+GNwMdSFgzVmfhNm8GJUX88AadB3uo9KpJqS3FaqNIPKgySuvMb+bHPsOmmuWyIcuqZj/pzt1RUIUZns4y2+A==}
peerDependencies:
@@ -5486,10 +5497,6 @@ packages:
resolution: {integrity: sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==}
engines: {node: '>=8'}
detect-libc@2.1.0:
resolution: {integrity: sha512-vEtk+OcP7VBRtQZ1EJ3bdgzSfBjgnEalLTp5zjJrS+2Z1w2KZly4SBdac/WDU3hhsNAZ9E8SC96ME4Ey8MZ7cg==}
engines: {node: '>=8'}
detect-newline@3.1.0:
resolution: {integrity: sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==}
engines: {node: '>=8'}
@@ -10916,19 +10923,19 @@ snapshots:
'@applitools/utils@1.7.7': {}
'@argos-ci/api-client@0.8.2':
'@argos-ci/api-client@0.8.1':
dependencies:
debug: 4.4.1(supports-color@8.1.1)
openapi-fetch: 0.13.5
transitivePeerDependencies:
- supports-color
'@argos-ci/browser@4.2.1': {}
'@argos-ci/browser@4.1.2': {}
'@argos-ci/core@3.2.3':
'@argos-ci/core@3.2.1':
dependencies:
'@argos-ci/api-client': 0.8.2
'@argos-ci/util': 2.3.3
'@argos-ci/api-client': 0.8.1
'@argos-ci/util': 2.3.2
axios: 1.8.4(debug@4.4.1)
convict: 6.2.4
debug: 4.4.1(supports-color@8.1.1)
@@ -10938,17 +10945,17 @@ snapshots:
transitivePeerDependencies:
- supports-color
'@argos-ci/cypress@5.0.7(cypress@14.5.1)':
'@argos-ci/cypress@5.0.2(cypress@14.5.1)':
dependencies:
'@argos-ci/browser': 4.2.1
'@argos-ci/core': 3.2.3
'@argos-ci/util': 2.3.3
'@argos-ci/browser': 4.1.2
'@argos-ci/core': 3.2.1
'@argos-ci/util': 2.3.2
cypress: 14.5.1
cypress-wait-until: 3.0.2
transitivePeerDependencies:
- supports-color
'@argos-ci/util@2.3.3': {}
'@argos-ci/util@2.3.2': {}
'@asamuzakjp/css-color@2.8.3':
dependencies:
@@ -11668,14 +11675,6 @@ snapshots:
'@babel/core': 7.28.4
'@babel/helper-plugin-utils': 7.27.1
'@babel/plugin-transform-explicit-resource-management@7.28.0(@babel/core@7.27.1)':
dependencies:
'@babel/core': 7.27.1
'@babel/helper-plugin-utils': 7.27.1
'@babel/plugin-transform-destructuring': 7.28.0(@babel/core@7.27.1)
transitivePeerDependencies:
- supports-color
'@babel/plugin-transform-explicit-resource-management@7.28.0(@babel/core@7.28.4)':
dependencies:
'@babel/core': 7.28.4
@@ -12140,7 +12139,7 @@ snapshots:
'@babel/helper-create-regexp-features-plugin': 7.27.1(@babel/core@7.28.4)
'@babel/helper-plugin-utils': 7.27.1
'@babel/preset-env@7.28.3(@babel/core@7.27.1)':
'@babel/preset-env@7.27.2(@babel/core@7.27.1)':
dependencies:
'@babel/compat-data': 7.28.4
'@babel/core': 7.27.1
@@ -12170,7 +12169,6 @@ snapshots:
'@babel/plugin-transform-duplicate-keys': 7.27.1(@babel/core@7.27.1)
'@babel/plugin-transform-duplicate-named-capturing-groups-regex': 7.27.1(@babel/core@7.27.1)
'@babel/plugin-transform-dynamic-import': 7.27.1(@babel/core@7.27.1)
'@babel/plugin-transform-explicit-resource-management': 7.28.0(@babel/core@7.27.1)
'@babel/plugin-transform-exponentiation-operator': 7.27.1(@babel/core@7.27.1)
'@babel/plugin-transform-export-namespace-from': 7.27.1(@babel/core@7.27.1)
'@babel/plugin-transform-for-of': 7.27.1(@babel/core@7.27.1)
@@ -12209,7 +12207,7 @@ snapshots:
'@babel/plugin-transform-unicode-sets-regex': 7.27.1(@babel/core@7.27.1)
'@babel/preset-modules': 0.1.6-no-external-plugins(@babel/core@7.27.1)
babel-plugin-polyfill-corejs2: 0.4.14(@babel/core@7.27.1)
babel-plugin-polyfill-corejs3: 0.13.0(@babel/core@7.27.1)
babel-plugin-polyfill-corejs3: 0.11.1(@babel/core@7.27.1)
babel-plugin-polyfill-regenerator: 0.6.5(@babel/core@7.27.1)
core-js-compat: 3.45.1
semver: 6.3.1
@@ -12879,11 +12877,11 @@ snapshots:
'@csstools/css-tokenizer@3.0.3': {}
'@cypress/code-coverage@3.13.4(@babel/core@7.27.1)(@babel/preset-env@7.28.3(@babel/core@7.27.1))(babel-loader@9.2.1(@babel/core@7.27.1)(webpack@5.95.0(esbuild@0.25.0)))(cypress@14.5.1)(webpack@5.95.0(esbuild@0.25.0))':
'@cypress/code-coverage@3.13.4(@babel/core@7.27.1)(@babel/preset-env@7.27.2(@babel/core@7.27.1))(babel-loader@9.2.1(@babel/core@7.27.1)(webpack@5.95.0(esbuild@0.25.0)))(cypress@14.5.1)(webpack@5.95.0(esbuild@0.25.0))':
dependencies:
'@babel/core': 7.27.1
'@babel/preset-env': 7.28.3(@babel/core@7.27.1)
'@cypress/webpack-preprocessor': 6.0.2(@babel/core@7.27.1)(@babel/preset-env@7.28.3(@babel/core@7.27.1))(babel-loader@9.2.1(@babel/core@7.27.1)(webpack@5.95.0(esbuild@0.25.0)))(webpack@5.95.0(esbuild@0.25.0))
'@babel/preset-env': 7.27.2(@babel/core@7.27.1)
'@cypress/webpack-preprocessor': 6.0.2(@babel/core@7.27.1)(@babel/preset-env@7.27.2(@babel/core@7.27.1))(babel-loader@9.2.1(@babel/core@7.27.1)(webpack@5.95.0(esbuild@0.25.0)))(webpack@5.95.0(esbuild@0.25.0))
babel-loader: 9.2.1(@babel/core@7.27.1)(webpack@5.95.0(esbuild@0.25.0))
chalk: 4.1.2
cypress: 14.5.1
@@ -12919,10 +12917,10 @@ snapshots:
tunnel-agent: 0.6.0
uuid: 8.3.2
'@cypress/webpack-preprocessor@6.0.2(@babel/core@7.27.1)(@babel/preset-env@7.28.3(@babel/core@7.27.1))(babel-loader@9.2.1(@babel/core@7.27.1)(webpack@5.95.0(esbuild@0.25.0)))(webpack@5.95.0(esbuild@0.25.0))':
'@cypress/webpack-preprocessor@6.0.2(@babel/core@7.27.1)(@babel/preset-env@7.27.2(@babel/core@7.27.1))(babel-loader@9.2.1(@babel/core@7.27.1)(webpack@5.95.0(esbuild@0.25.0)))(webpack@5.95.0(esbuild@0.25.0))':
dependencies:
'@babel/core': 7.27.1
'@babel/preset-env': 7.28.3(@babel/core@7.27.1)
'@babel/preset-env': 7.27.2(@babel/core@7.27.1)
babel-loader: 9.2.1(@babel/core@7.27.1)(webpack@5.95.0(esbuild@0.25.0))
bluebird: 3.7.1
debug: 4.4.1(supports-color@8.1.1)
@@ -15537,7 +15535,7 @@ snapshots:
transitivePeerDependencies:
- supports-color
babel-plugin-polyfill-corejs3@0.13.0(@babel/core@7.27.1):
babel-plugin-polyfill-corejs3@0.11.1(@babel/core@7.27.1):
dependencies:
'@babel/core': 7.27.1
'@babel/helper-define-polyfill-provider': 0.6.5(@babel/core@7.27.1)
@@ -16801,8 +16799,6 @@ snapshots:
detect-libc@2.0.3: {}
detect-libc@2.1.0: {}
detect-newline@3.1.0: {}
detect-node@2.1.0: {}
@@ -21158,7 +21154,7 @@ snapshots:
sharp@0.33.5:
dependencies:
color: 4.2.3
detect-libc: 2.1.0
detect-libc: 2.0.3
semver: 7.7.2
optionalDependencies:
'@img/sharp-darwin-arm64': 0.33.5