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 + ); } };