UNPKG

mermaid-it-markdown

Version:

一个markdown-it的插件,用于支持mermaid语法的渲染

2 lines (1 loc) 1.84 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mermaid")):"function"==typeof define&&define.amd?define(["exports","mermaid"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).MermaidItMarkdown={},e.mermaid)}(this,(function(e,t){"use strict";let n;const r=new Uint8Array(16);function o(){if(!n&&(n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!n))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return n(r)}const i=[];for(let s=0;s<256;++s)i.push((s+256).toString(16).slice(1));const d={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function u(e,t,n){if(d.randomUUID&&!t&&!e)return d.randomUUID();const r=(e=e||{}).random||(e.rng||o)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return i[e[t+0]]+i[e[t+1]]+i[e[t+2]]+i[e[t+3]]+"-"+i[e[t+4]]+i[e[t+5]]+"-"+i[e[t+6]]+i[e[t+7]]+"-"+i[e[t+8]]+i[e[t+9]]+"-"+i[e[t+10]]+i[e[t+11]]+i[e[t+12]]+i[e[t+13]]+i[e[t+14]]+i[e[t+15]]}(r)}const a=(e="")=>u().split("-").join(e),c=async e=>new Promise((t=>{setTimeout(t,e)}));e.default=function(e){t.initialize({startOnLoad:!1});const n=e.renderer.rules.fence.bind(e.renderer.rules);e.renderer.rules.fence=(e,r,o,i,d)=>{const u=e[r];if("mermaid"===u.info.trim()){const e="mermaid-container-"+a();(async(e,n)=>{let r=100;for(;r-- >0;){const r=document.getElementById(n);if(r){try{const{svg:n}=await t.render("mermaid-svg-"+a(),e,r);r.innerHTML=n}catch(o){}break}await c(100)}})(u.content,e).then();const n=document.createElement("div");return n.id=e,n.outerHTML}return n(e,r,o,i,d)}},Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));