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 => {