Skip to content

Commit

Permalink
Merge pull request #3222 from leon19/bugfix/incorrect-label-padding
Browse files Browse the repository at this point in the history
fix: remove right padding when a label contains HTML entities
  • Loading branch information
knsv committed Aug 4, 2022
2 parents 1e1f272 + c40368b commit b0074bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions cypress/integration/rendering/stateDiagram-v2.spec.js
Expand Up @@ -509,4 +509,16 @@ stateDiagram-v2
expect(svg).to.not.have.attr('style');
});
});

it('v2 should render a state diagram and set the correct length of the labels', () => {
imgSnapshotTest(
`
stateDiagram-v2
[*] --> 1
1 --> 2: test({ foo#colon; 'far' })
2 --> [*]
`,
{ logLevel: 0, fontFamily: 'courier' }
);
});
});
3 changes: 2 additions & 1 deletion src/dagre-wrapper/createLabel.js
Expand Up @@ -2,6 +2,7 @@ import { select } from 'd3';
import { log } from '../logger'; // eslint-disable-line
import { getConfig } from '../config';
import { sanitizeText, evaluate } from '../diagrams/common/common';
import { decodeEntities } from '../mermaidAPI';

const sanitizeTxt = (txt) => sanitizeText(txt, getConfig());

Expand Down Expand Up @@ -52,7 +53,7 @@ const createLabel = (_vertexText, style, isTitle, isNode) => {
log.info('vertexText' + vertexText);
const node = {
isNode,
label: vertexText.replace(
label: decodeEntities(vertexText).replace(
/fa[lrsb]?:fa-[\w-]+/g,
(s) => `<i class='${s.replace(':', ' ')}'></i>`
),
Expand Down

0 comments on commit b0074bf

Please sign in to comment.