From 8210e3c80acf6bf0941b78fd291d192af60edbf0 Mon Sep 17 00:00:00 2001 From: Tim Maffett Date: Thu, 5 May 2022 11:47:46 -0700 Subject: [PATCH] add setParseErrorHandler,check for undefined mermaidAPI before using --- src/mermaid.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/mermaid.js b/src/mermaid.js index 38391c941..e2475c601 100644 --- a/src/mermaid.js +++ b/src/mermaid.js @@ -188,18 +188,38 @@ if (typeof document !== 'undefined') { ); } +/** + * ## setParseErrorHandler Alternativet to directly setting parseError using: + * + * ```js + * mermaid.parseError = function(err,hash){= + * forExampleDisplayErrorInGui(err); // do something with the error + * }; + * ``` + * + * This is provided for environments where the mermaid object can't directly have a new member added + * to it (eg. dart interop wrapper). (Initially there is no parseError member of mermaid). + * + * @param {function (err, hash)} newParseErrorHandler New parseError() callback. + */ +const setParseErrorHandler = function (newParseErrorHandler) { + mermaid.parseError = newParseErrorHandler; +}; + const mermaid = { startOnLoad: true, htmlLabels: true, mermaidAPI, - parse: mermaidAPI.parse, - render: mermaidAPI.render, + parse: mermaidAPI != undefined ? mermaidAPI.parse : null, + render: mermaidAPI != undefined ? mermaidAPI.render : null, init, initialize, contentLoaded, + + setParseErrorHandler, }; export default mermaid;