diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/erBox.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/erBox.ts index 2c812b862..937d3a921 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/erBox.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/erBox.ts @@ -280,29 +280,27 @@ async function addText( labelText = labelText.replaceAll('<', '<').replaceAll('>', '>'); } - const text = label - .node() - .appendChild( - await createText( - label, - labelText, - { - width: calculateTextWidth(labelText, config) + 100, - style, - useHtmlLabels: config.htmlLabels, - }, - config - ) - ); + const text = label.node().appendChild( + await createText( + label, + labelText, + { + width: calculateTextWidth(labelText, config) + 100, + style, + useHtmlLabels: config.htmlLabels, + }, + config + ) + ); // Undo work around now that text passed through correctly - if (labelText.includes('<')) { + if (labelText.includes('<') || labelText.includes('>')) { let child = text.children[0]; - // Get last child + child.textContent = child.textContent.replaceAll('<', '<').replaceAll('>', '>'); while (child.childNodes[0]) { child = child.childNodes[0]; + // Replace its text content + child.textContent = child.textContent.replaceAll('<', '<').replaceAll('>', '>'); } - // Replace its text content - child.textContent = child.textContent.replaceAll('<', '<').replaceAll('>', '>'); } let bbox = text.getBBox();