From 473aced449406aa8dd0289b030fd38c1550e88e8 Mon Sep 17 00:00:00 2001 From: Mindaugas Laganeckas Date: Tue, 19 Apr 2022 17:21:10 +0200 Subject: [PATCH] Add initThrowsErrors() (#2379) * Add initThrowsErrors() * Update mermaid.js * Update mermaid.js --- src/mermaid.js | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/mermaid.js b/src/mermaid.js index 5d7a0090f..38391c941 100644 --- a/src/mermaid.js +++ b/src/mermaid.js @@ -30,6 +30,18 @@ import utils from './utils'; * Renders the mermaid diagrams */ const init = function () { + try { + initThrowsErrors(); + } catch (e) { + log.warn('Syntax Error rendering'); + log.warn(e); + if (this.parseError) { + this.parseError(e); + } + } +}; + +const initThrowsErrors = function () { const conf = mermaidAPI.getConfig(); // console.log('Starting rendering diagrams (init) - mermaid.init', conf); let nodes; @@ -109,26 +121,18 @@ const init = function () { log.debug('Detected early reinit: ', init); } - try { - mermaidAPI.render( - id, - txt, - (svgCode, bindFunctions) => { - element.innerHTML = svgCode; - if (typeof callback !== 'undefined') { - callback(id); - } - if (bindFunctions) bindFunctions(element); - }, - element - ); - } catch (e) { - log.warn('Syntax Error rendering'); - log.warn(e); - if (this.parseError) { - this.parseError(e); - } - } + mermaidAPI.render( + id, + txt, + (svgCode, bindFunctions) => { + element.innerHTML = svgCode; + if (typeof callback !== 'undefined') { + callback(id); + } + if (bindFunctions) bindFunctions(element); + }, + element + ); } };