diff --git a/.husky/pre-commit b/.husky/pre-commit index e8191928d4..ad85fc42c2 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -NODE_OPTIONS=--max_old_space_size=8192 pnpm run pre-commit +NODE_OPTIONS="--max_old_space_size=8192" pnpm run pre-commit diff --git a/cypress/integration/rendering/flowchart-v2.spec.js b/cypress/integration/rendering/flowchart-v2.spec.js index 857d395be7..5b358e051f 100644 --- a/cypress/integration/rendering/flowchart-v2.spec.js +++ b/cypress/integration/rendering/flowchart-v2.spec.js @@ -904,6 +904,18 @@ end ); }); }); + + it('should not auto wrap when markdownAutoWrap is false', () => { + imgSnapshotTest( + `flowchart TD + angular_velocity["\`**angular_velocity** + *angular_displacement / duration* + [rad/s, 1/s] + {vector}\`"] + frequency["frequency\n(1 / period_duration)\n[Hz, 1/s]"]`, + { markdownAutoWrap: false } + ); + }); }); describe('Subgraph title margins', () => { it('Should render subgraphs with title margins set (LR)', () => { diff --git a/docs/config/setup/modules/config.md b/docs/config/setup/modules/config.md index f1de64e2df..48e6875779 100644 --- a/docs/config/setup/modules/config.md +++ b/docs/config/setup/modules/config.md @@ -50,7 +50,7 @@ Pushes in a directive to the configuration | --------- | ------------------------- | ----------- | ------------------------------ | | getConfig | Obtains the currentConfig | Get Request | Any Values from current Config | -**Notes**: Returns **any** the currentConfig +**Notes**: Avoid calling this function repeatedly. Instead, store the result in a variable and use it, and pass it down to function calls. #### Returns diff --git a/docs/syntax/flowchart.md b/docs/syntax/flowchart.md index 3f4e9b04af..83676b0e41 100644 --- a/docs/syntax/flowchart.md +++ b/docs/syntax/flowchart.md @@ -852,6 +852,16 @@ Formatting: This feature is applicable to node labels, edge labels, and subgraph labels. +The auto wrapping can be disabled by using + +``` +--- +config: + markdownAutoWrap: false +--- +graph LR +``` + ## Interaction It is possible to bind a click event to a node, the click can lead to either a javascript callback or to a link which will be opened in a new browser tab. diff --git a/packages/mermaid/src/config.ts b/packages/mermaid/src/config.ts index ede3a568df..4168c24c4f 100644 --- a/packages/mermaid/src/config.ts +++ b/packages/mermaid/src/config.ts @@ -124,7 +124,7 @@ export const setConfig = (conf: MermaidConfig): MermaidConfig => { * | --------- | ------------------------- | ----------- | ------------------------------ | * | getConfig | Obtains the currentConfig | Get Request | Any Values from current Config | * - * **Notes**: Returns **any** the currentConfig + * **Notes**: Avoid calling this function repeatedly. Instead, store the result in a variable and use it, and pass it down to function calls. * * @returns The currentConfig */ diff --git a/packages/mermaid/src/config.type.ts b/packages/mermaid/src/config.type.ts index 2ff19c2d6e..79f4243151 100644 --- a/packages/mermaid/src/config.type.ts +++ b/packages/mermaid/src/config.type.ts @@ -159,6 +159,7 @@ export interface MermaidConfig { dompurifyConfig?: DOMPurifyConfiguration; wrap?: boolean; fontSize?: number; + markdownAutoWrap?: boolean; /** * Suppresses inserting 'Syntax error' diagram in the DOM. * This is useful when you want to control how to handle syntax errors in your application. diff --git a/packages/mermaid/src/dagre-wrapper/clusters.js b/packages/mermaid/src/dagre-wrapper/clusters.js index 9dde401878..2c77468769 100644 --- a/packages/mermaid/src/dagre-wrapper/clusters.js +++ b/packages/mermaid/src/dagre-wrapper/clusters.js @@ -30,7 +30,7 @@ const rect = (parent, node) => { // .appendChild(createLabel(node.labelText, node.labelStyle, undefined, true)); const text = node.labelType === 'markdown' - ? createText(label, node.labelText, { style: node.labelStyle, useHtmlLabels }) + ? createText(label, node.labelText, { style: node.labelStyle, useHtmlLabels }, siteConfig) : label.node().appendChild(createLabel(node.labelText, node.labelStyle, undefined, true)); // Get the size of the label diff --git a/packages/mermaid/src/dagre-wrapper/edges.js b/packages/mermaid/src/dagre-wrapper/edges.js index 6f7e4695d4..1a72328e81 100644 --- a/packages/mermaid/src/dagre-wrapper/edges.js +++ b/packages/mermaid/src/dagre-wrapper/edges.js @@ -18,15 +18,21 @@ export const clear = () => { }; export const insertEdgeLabel = (elem, edge) => { - const useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels); + const config = getConfig(); + const useHtmlLabels = evaluate(config.flowchart.htmlLabels); // Create the actual text element const labelElement = edge.labelType === 'markdown' - ? createText(elem, edge.label, { - style: edge.labelStyle, - useHtmlLabels, - addSvgBackground: true, - }) + ? createText( + elem, + edge.label, + { + style: edge.labelStyle, + useHtmlLabels, + addSvgBackground: true, + }, + config + ) : createLabel(edge.label, edge.labelStyle); // Create outer g, edgeLabel, this will be positioned after graph layout diff --git a/packages/mermaid/src/dagre-wrapper/shapes/util.js b/packages/mermaid/src/dagre-wrapper/shapes/util.js index df2c27bd5a..1d0d2d77e6 100644 --- a/packages/mermaid/src/dagre-wrapper/shapes/util.js +++ b/packages/mermaid/src/dagre-wrapper/shapes/util.js @@ -6,8 +6,9 @@ import { evaluate, sanitizeText } from '../../diagrams/common/common.js'; import { decodeEntities } from '../../utils.js'; export const labelHelper = async (parent, node, _classes, isNode) => { + const config = getConfig(); let classes; - const useHtmlLabels = node.useHtmlLabels || evaluate(getConfig().flowchart.htmlLabels); + const useHtmlLabels = node.useHtmlLabels || evaluate(config.flowchart.htmlLabels); if (!_classes) { classes = 'node default'; } else { @@ -35,26 +36,26 @@ export const labelHelper = async (parent, node, _classes, isNode) => { let text; if (node.labelType === 'markdown') { // text = textNode; - text = createText(label, sanitizeText(decodeEntities(labelText), getConfig()), { - useHtmlLabels, - width: node.width || getConfig().flowchart.wrappingWidth, - classes: 'markdown-node-label', - }); + text = createText( + label, + sanitizeText(decodeEntities(labelText), config), + { + useHtmlLabels, + width: node.width || config.flowchart.wrappingWidth, + classes: 'markdown-node-label', + }, + config + ); } else { text = textNode.appendChild( - createLabel( - sanitizeText(decodeEntities(labelText), getConfig()), - node.labelStyle, - false, - isNode - ) + createLabel(sanitizeText(decodeEntities(labelText), config), node.labelStyle, false, isNode) ); } // Get the size of the label let bbox = text.getBBox(); const halfPadding = node.padding / 2; - if (evaluate(getConfig().flowchart.htmlLabels)) { + if (evaluate(config.flowchart.htmlLabels)) { const div = text.children[0]; const dv = select(text); @@ -76,8 +77,8 @@ export const labelHelper = async (parent, node, _classes, isNode) => { if (noImgText) { // default size if no text - const bodyFontSize = getConfig().fontSize - ? getConfig().fontSize + const bodyFontSize = config.fontSize + ? config.fontSize : window.getComputedStyle(document.body).fontSize; const enlargingFactor = 5; const width = parseInt(bodyFontSize, 10) * enlargingFactor + 'px'; diff --git a/packages/mermaid/src/diagrams/common/common.ts b/packages/mermaid/src/diagrams/common/common.ts index 04be2a5f46..017b2b0911 100644 --- a/packages/mermaid/src/diagrams/common/common.ts +++ b/packages/mermaid/src/diagrams/common/common.ts @@ -346,11 +346,9 @@ export const renderKatex = async (text: string, config: MermaidConfig): Promise< .split(lineBreakRegex) .map((line) => hasKatex(line) - ? ` -
Hello
Unsupported markdown: list"'); }); + +test('markdownToHTML - no auto wrapping', () => { + expect( + markdownToHTML( + `Hello, how do + you do?`, + { markdownAutoWrap: false } + ) + ).toMatchInlineSnapshot('"Hello, how do
you do?