diff --git a/public/js/extra.js b/public/js/extra.js index 53fdc76b5..47b5a916a 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -254,7 +254,10 @@ function replaceExtraTags (html) { } if (typeof window.mermaid !== 'undefined' && window.mermaid) { - window.mermaid.startOnLoad = false + window.mermaid.initialize({ + startOnLoad: false + }) + window.mermaid.parseError = function (err, hash) { console.warn(err) } @@ -433,22 +436,26 @@ export function finishView (view) { }) // mermaid const mermaids = view.find('div.mermaid.raw').removeClass('raw') - mermaids.each((key, value) => { + mermaids.each(async (key, value) => { + const $value = $(value) + const $ele = $value.closest('pre') try { - var $value = $(value) - const $ele = $(value).closest('pre') - const text = $value.text() // validate the syntax first if (window.mermaid.parse(text)) { $ele.addClass('mermaid') $ele.text(text) // render the diagram - window.mermaid.init(undefined, $ele) + const id = `mermaid-${Date.now()}-${Math.random().toString(36).substr(2, 9)}` + const { svg, bindFunctions } = await window.mermaid.render(id, text, $ele[0]) + $ele.html(svg) + if (bindFunctions) { + bindFunctions($ele[0]) + } } } catch (err) { $value.unwrap() - $value.parent().append(`