From 2c5d83fab3c7e0472ac9f6e51c4ece21a445af4d Mon Sep 17 00:00:00 2001 From: rhysd Date: Sun, 30 Apr 2023 00:32:40 +0900 Subject: [PATCH] Add `suppressErrorRendering` option to avoid inserting 'Syntax error' message in diagram --- packages/mermaid/src/config.type.ts | 1 + packages/mermaid/src/defaultConfig.ts | 8 ++++++++ packages/mermaid/src/mermaidAPI.ts | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/mermaid/src/config.type.ts b/packages/mermaid/src/config.type.ts index 545fdbbfb..207ca60d8 100644 --- a/packages/mermaid/src/config.type.ts +++ b/packages/mermaid/src/config.type.ts @@ -34,6 +34,7 @@ export interface MermaidConfig { dompurifyConfig?: DOMPurify.Config; wrap?: boolean; fontSize?: number; + suppressErrorRendering?: boolean; } // TODO: More configs needs to be moved in here diff --git a/packages/mermaid/src/defaultConfig.ts b/packages/mermaid/src/defaultConfig.ts index 9c6d6f46e..00c054358 100644 --- a/packages/mermaid/src/defaultConfig.ts +++ b/packages/mermaid/src/defaultConfig.ts @@ -152,6 +152,14 @@ const config: Partial = { */ deterministicIDSeed: undefined, + /** + * This option suppresses inserting 'Syntax error' message in diagram. This option is useful when + * you want to control how to handle syntax error in your application. + * + * Default value: false + */ + suppressErrorRendering: false, + /** The object containing configurations specific for flowcharts */ flowchart: { /** diff --git a/packages/mermaid/src/mermaidAPI.ts b/packages/mermaid/src/mermaidAPI.ts index 5e9d0ead6..b31378ce6 100644 --- a/packages/mermaid/src/mermaidAPI.ts +++ b/packages/mermaid/src/mermaidAPI.ts @@ -511,7 +511,9 @@ const render = async function ( try { await diag.renderer.draw(text, id, version, diag); } catch (e) { - errorRenderer.draw(text, id, version); + if (!config.suppressErrorRendering) { + errorRenderer.draw(text, id, version); + } throw e; } @@ -617,6 +619,7 @@ function addA11yInfo( * securityLevel: 'strict', * startOnLoad: true, * arrowMarkerAbsolute: false, + * suppressErrorRendering: false, * * er: { * diagramPadding: 20,