@mdit/plugin-plantuml
Version:
plantuml plugin for MarkdownIt
5 lines (4 loc) • 1.25 kB
JavaScript
import{deflateRawSync as w}from"node:zlib";import{uml as v}from"@mdit/plugin-uml";const y=e=>w(Buffer.from(e,"utf8"),{level:9}).toString("binary"),s=e=>e<10?String.fromCharCode(48+e):e<36?String.fromCharCode(65+e-10):e<62?String.fromCharCode(97+e-36):e===62?"-":e===63?"_":"?",C=(e,r,t)=>{const f=e>>2,d=(e&3)<<4|r>>4,u=(r&15)<<2|t>>6,h=t&63;return s(f&63)+s(d&63)+s(u&63)+s(h&63)},B=e=>{let r="";for(let t=0;t<e.length;t+=3)t+2===e.length?r+=C(e.charCodeAt(t),e.charCodeAt(t+1),0):t+1===e.length?r+=C(e.charCodeAt(t),0,0):r+=C(e.charCodeAt(t),e.charCodeAt(t+1),e.charCodeAt(t+2));return r},P=(e,{type:r="uml",name:t="uml",open:f=`start${t}`,close:d=`end${t}`,fence:u=t,format:h="svg",server:$="https://www.plantuml.com/plantuml",srcGetter:A=o=>`${$}/${h}/${B(y(`@start${t}
${o.trim()}
@end${t}`))}`,render:g=(o,a,l,i,c)=>{const n=o[a],{content:m,info:p="plantuml diagram"}=n;return n.tag="img",n.attrPush(["src",A(m)]),n.attrPush(["alt",p]),c.renderToken(o,a,l)}}={})=>{if(r==="uml")e.use(v,{name:t,open:f,close:d,render:g});else{const o=e.renderer.rules.fence;e.renderer.rules.fence=(a,l,i,c,n)=>{const m=a[l],[p,S]=m.info.split(" ",2);return p===u?(m.info=S,g(a,l,i,c,n)):o(a,l,i,c,n)}}};export{P as plantuml};
//# sourceMappingURL=index.js.map