From fe8932e906bce3d1856b8dcd1dcf3ed946251a38 Mon Sep 17 00:00:00 2001 From: yari-dewalt Date: Tue, 29 Oct 2024 11:54:25 -0700 Subject: [PATCH 1/3] Set node.centerLabel before using labelHelper() --- .../src/rendering-util/rendering-elements/shapes/note.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/note.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/note.ts index 403294783e..dfad92949e 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/note.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/note.ts @@ -4,6 +4,7 @@ import intersect from '../intersect/index.js'; import { styles2String, userNodeOverrides } from './handDrawnShapeStyles.js'; import { getNodeClasses, labelHelper, updateNodeBounds } from './util.js'; import type { D3Selection } from '../../../types.js'; +import { getConfig } from '../../../config.js'; export async function note( parent: D3Selection, @@ -12,16 +13,16 @@ export async function note( ) { const { labelStyles, nodeStyles } = styles2String(node); node.labelStyle = labelStyles; + const useHtmlLabels = node.useHtmlLabels || getConfig().htmlLabels; + if (!useHtmlLabels) { + node.centerLabel = true; + } const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node)); const totalWidth = Math.max(bbox.width + (node.padding ?? 0) * 2, node?.width ?? 0); const totalHeight = Math.max(bbox.height + (node.padding ?? 0) * 2, node?.height ?? 0); const x = -totalWidth / 2; const y = -totalHeight / 2; const { cssStyles } = node; - const useHtmlLabels = node.useHtmlLabels; - if (!useHtmlLabels) { - node.centerLabel = true; - } // add the rect // @ts-ignore TODO: Fix rough typings From 8f0e0b9c39fd6cd14549c6896088ee29b7c91851 Mon Sep 17 00:00:00 2001 From: yari-dewalt Date: Tue, 29 Oct 2024 11:55:34 -0700 Subject: [PATCH 2/3] Change useHtmlLabels to use general config's htmlLabels attribute not flowchart's --- .../src/rendering-util/rendering-elements/shapes/util.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/util.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/util.ts index 883129e9a8..7dead8ad07 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/util.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/util.ts @@ -13,7 +13,7 @@ export const labelHelper = async ( _classes?: string ) => { let cssClasses; - const useHtmlLabels = node.useHtmlLabels || evaluate(getConfig()?.flowchart?.htmlLabels); + const useHtmlLabels = node.useHtmlLabels || evaluate(getConfig()?.htmlLabels); if (!_classes) { cssClasses = 'node default'; } else { @@ -52,7 +52,7 @@ export const labelHelper = async ( let bbox = text.getBBox(); const halfPadding = (node?.padding ?? 0) / 2; - if (evaluate(getConfig().flowchart?.htmlLabels)) { + if (useHtmlLabels) { const div = text.children[0]; const dv = select(text); From c34fd152d569c64d9148f68d2b061e99db92d80c Mon Sep 17 00:00:00 2001 From: yari-dewalt Date: Tue, 29 Oct 2024 11:57:22 -0700 Subject: [PATCH 3/3] Add handling for ' characters in non-html text so they don't get sanitized into html code values --- packages/mermaid/src/rendering-util/handle-markdown-text.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/mermaid/src/rendering-util/handle-markdown-text.ts b/packages/mermaid/src/rendering-util/handle-markdown-text.ts index 1bff5a9776..f898875cf0 100644 --- a/packages/mermaid/src/rendering-util/handle-markdown-text.ts +++ b/packages/mermaid/src/rendering-util/handle-markdown-text.ts @@ -39,6 +39,7 @@ export function markdownToLines(markdown: string, config: MermaidConfig = {}): M lines.push([]); } textLine.split(' ').forEach((word) => { + word = word.replace(/'/g, `'`); if (word) { lines[currentLine].push({ content: word, type: parentType }); }