diff --git a/packages/mermaid/src/diagrams/class/classTypes.ts b/packages/mermaid/src/diagrams/class/classTypes.ts index d112772da..29d668344 100644 --- a/packages/mermaid/src/diagrams/class/classTypes.ts +++ b/packages/mermaid/src/diagrams/class/classTypes.ts @@ -123,42 +123,13 @@ export class ClassMember { } this.classifier = potentialClassifier; - // TODO: Right now getting rid of spacing in id / name, TODO: Add optional spacing - const combinedText = `${this.visibility}${this.id}${this.memberType === 'method' ? `(${this.parameters})${this.returnType ? ' : ' + this.returnType : ''}` : ''}`; - this.text = combinedText; - if (combinedText.includes('~')) { - const numOfTildes = (combinedText.substring(1).match(/~/g) ?? []).length; - let count = numOfTildes; - if (count !== 1) { - const odd = count % 2 > 0; + // Preserve one space only + this.id = this.id.startsWith(' ') ? ' ' + this.id.trim() : this.id.trim(); - // Replace all '~' with '>' - let replacedRaw = combinedText.substring(1).replaceAll('~', '>'); - - // Replace the first half of '>' with '<' - while (count > 0) { - replacedRaw = replacedRaw.replace('>', '<'); - count -= 2; // Each iteration replaces one '>' with '<', so reduce count by 2 - } - if (odd) { - // Replace first occurrence. - if (this.memberType === 'method') { - replacedRaw = replacedRaw.replace('<', '~'); - } else { - // Replace middle occurrence. - const ltOccurrences = replacedRaw.match(/</g) ?? []; - if (ltOccurrences.length > 1) { - let ltCount = 0; - - replacedRaw = replacedRaw.replace('<', (match) => { - ltCount++; - return ltCount === ltOccurrences.length ? '~' : match; - }); - } - } - } - this.text = this.text.charAt(0) + replacedRaw; - } + const combinedText = `${this.visibility ? '\\' + this.visibility : ''}${parseGenericTypes(this.id)}${this.memberType === 'method' ? `(${parseGenericTypes(this.parameters)})${this.returnType ? ' : ' + parseGenericTypes(this.returnType) : ''}` : ''}`; + this.text = combinedText.replaceAll('<', '<').replaceAll('>', '>'); + if (this.text.startsWith('\\<')) { + this.text = this.text.replace('\\<', '~'); } } diff --git a/packages/mermaid/src/diagrams/class/shapeUtil.ts b/packages/mermaid/src/diagrams/class/shapeUtil.ts index 0b4d2c047..1c963b87d 100644 --- a/packages/mermaid/src/diagrams/class/shapeUtil.ts +++ b/packages/mermaid/src/diagrams/class/shapeUtil.ts @@ -109,6 +109,12 @@ const addText = async ( textContent = node.label!; } + // createText() will cause unwanted behavior because of classDiagram syntax so workarounds are needed + + if (!useHtmlLabels && textContent.startsWith('\\')) { + textContent = textContent.substring(1); + } + if (hasKatex(textContent)) { useHtmlLabels = true; } @@ -126,7 +132,6 @@ const addText = async ( let bbox; let numberOfLines = 1; - // createText() creates unwanted behavior because of syntax, so fix if (!useHtmlLabels) { // Undo font-weight select(text).selectAll('tspan').attr('font-weight', ''); diff --git a/packages/mermaid/src/rendering-util/handle-markdown-text.ts b/packages/mermaid/src/rendering-util/handle-markdown-text.ts index 89a20d0cb..1bff5a977 100644 --- a/packages/mermaid/src/rendering-util/handle-markdown-text.ts +++ b/packages/mermaid/src/rendering-util/handle-markdown-text.ts @@ -87,8 +87,6 @@ export function markdownToHTML(markdown: string, { markdownAutoWrap }: MermaidCo return `${node.text}`; } else if (node.type === 'escape') { return node.text; - } else if (node.type === 'list') { - return node.raw; } return `Unsupported markdown: ${node.type}`; }