mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-21 06:53:17 +08:00
19 lines
655 B
JavaScript
19 lines
655 B
JavaScript
const createLabel = (vertexText, style) => {
|
|
const svgLabel = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
|
svgLabel.setAttribute('style', style.replace('color:', 'fill:'));
|
|
|
|
const rows = vertexText.split(/<br\s*\/?>/gi);
|
|
|
|
for (let j = 0; j < rows.length; j++) {
|
|
const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
|
|
tspan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
|
|
tspan.setAttribute('dy', '1em');
|
|
tspan.setAttribute('x', '0');
|
|
tspan.textContent = rows[j];
|
|
svgLabel.appendChild(tspan);
|
|
}
|
|
return svgLabel;
|
|
};
|
|
|
|
export default createLabel;
|