From a08c3930f8bb06ea1ca93b12194973e8ef4eb47c Mon Sep 17 00:00:00 2001 From: nour kouider Date: Sun, 23 Feb 2025 20:19:02 +0100 Subject: [PATCH 1/3] fix(mindmap): correctly render ampersand (&) --- packages/mermaid/src/rendering-util/createText.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mermaid/src/rendering-util/createText.ts b/packages/mermaid/src/rendering-util/createText.ts index cc189e46e7..1985393db6 100644 --- a/packages/mermaid/src/rendering-util/createText.ts +++ b/packages/mermaid/src/rendering-util/createText.ts @@ -169,7 +169,7 @@ function updateTextContentAndStyles(tspan: any, wrappedLine: MarkdownWord[]) { .attr('class', 'text-inner-tspan') .attr('font-weight', word.type === 'strong' ? 'bold' : 'normal'); if (index === 0) { - innerTspan.text(word.content); + innerTspan.html(word.content); } else { // TODO: check what joiner to use. innerTspan.text(' ' + word.content); From f91fea26bbfbe7a74a1b3e222bbbb5b32d1c7c96 Mon Sep 17 00:00:00 2001 From: nour kouider Date: Mon, 24 Feb 2025 08:42:30 +0100 Subject: [PATCH 2/3] fix(mindmap): properly render ampersand without affecting other diagrams --- packages/mermaid/src/diagrams/mindmap/mindmapDb.ts | 5 ++++- packages/mermaid/src/rendering-util/createText.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts b/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts index e7041e9d66..310e2b02d1 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts +++ b/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts @@ -44,7 +44,10 @@ const addNode = (level: number, id: string, descr: string, type: number) => { id: cnt++, nodeId: sanitizeText(id, conf), level, - descr: sanitizeText(descr, conf), + descr: sanitizeText(descr, conf) + .replace(/&/g, '&') + .replace(/>/g, '>') + .replace(/</g, '<'), type, children: [], width: conf.mindmap?.maxNodeWidth ?? defaultConfig.mindmap.maxNodeWidth, diff --git a/packages/mermaid/src/rendering-util/createText.ts b/packages/mermaid/src/rendering-util/createText.ts index 1985393db6..cc189e46e7 100644 --- a/packages/mermaid/src/rendering-util/createText.ts +++ b/packages/mermaid/src/rendering-util/createText.ts @@ -169,7 +169,7 @@ function updateTextContentAndStyles(tspan: any, wrappedLine: MarkdownWord[]) { .attr('class', 'text-inner-tspan') .attr('font-weight', word.type === 'strong' ? 'bold' : 'normal'); if (index === 0) { - innerTspan.html(word.content); + innerTspan.text(word.content); } else { // TODO: check what joiner to use. innerTspan.text(' ' + word.content); From 79fa79aad3380f60ac063d0ac2b301523a7bab64 Mon Sep 17 00:00:00 2001 From: nour kouider Date: Mon, 24 Feb 2025 15:40:13 +0100 Subject: [PATCH 3/3] fix(mindmap): correct ampersand replacement order --- packages/mermaid/src/diagrams/mindmap/mindmapDb.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts b/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts index 310e2b02d1..e6009b4cf5 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts +++ b/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts @@ -45,9 +45,9 @@ const addNode = (level: number, id: string, descr: string, type: number) => { nodeId: sanitizeText(id, conf), level, descr: sanitizeText(descr, conf) - .replace(/&/g, '&') .replace(/>/g, '>') - .replace(/</g, '<'), + .replace(/</g, '<') + .replace(/&/g, '&'), type, children: [], width: conf.mindmap?.maxNodeWidth ?? defaultConfig.mindmap.maxNodeWidth,