From 6334d4ab84ece14fd66d5a7b2f66c66d0dff1912 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Thu, 17 Aug 2023 14:26:04 +0530 Subject: [PATCH] fix: Error diagram rendering --- src/lib/util/mermaid.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/util/mermaid.ts b/src/lib/util/mermaid.ts index 53c00788..3f3ebe68 100644 --- a/src/lib/util/mermaid.ts +++ b/src/lib/util/mermaid.ts @@ -8,7 +8,19 @@ export const render = async ( ): Promise => { // Should be able to call this multiple times without any issues. mermaid.initialize(config); - return await mermaid.render(id, code); + + try { + const result = await mermaid.render(id, code); + return result; + } catch { + const errorDiv = document.querySelector(`#d${id}`); + const svg = errorDiv?.innerHTML ?? ''; + errorDiv?.remove(); + return { + svg, + bindFunctions: undefined + }; + } }; export const parse = async (code: string): Promise => {