UNPKG

quikdown

Version:

Small, safe, bidirectional Markdown parser and editor with streaming, undo/redo, rich fences, MCP tools, and a standalone airgapped build. Zero runtime deps. Browser and Node.js.

9 lines (8 loc) • 18 kB
/** * quikdown - Lightweight Markdown Parser * @version 1.2.22 * @license BSD-2-Clause * @copyright DeftIO 2025 */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).quikdown=t()}(this,function(){"use strict";function e(e){if(e.length<3)return!1;let t="";for(let n=0;n<e.length;n++){const r=e[n];" "!==r&&"\t"!==r&&(t+=r)}if(t.length<3)return!1;const n=t[0];if("-"!==n&&"*"!==n&&"_"!==n)return!1;for(let e=1;e<t.length;e++)if(t[e]!==n)return!1;return!0}const t="quikdown-",n="§CB",r="§HT",o="§BE",l="§NL§",s={href:1,src:1,action:1,formaction:1},i={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},a={h1:"font-size:2em;margin:.67em 0;text-align:left",h2:"font-size:1.5em;margin:.83em 0",h3:"font-size:1.25em;margin:1em 0",h4:"font-size:1em;margin:1.33em 0",h5:"font-size:.875em;margin:1.67em 0",h6:"font-size:.85em;margin:2em 0",pre:"background:#f4f4f4;padding:10px;border-radius:4px;overflow-x:auto;margin:1em 0",code:"background:#f0f0f0;padding:2px 4px;border-radius:3px;font-family:monospace",blockquote:"border-left:4px solid #ddd;margin-left:0;padding-left:1em",table:"border-collapse:collapse;width:100%;margin:1em 0",th:"border:1px solid #ddd;padding:8px;background-color:#f2f2f2;font-weight:bold;text-align:left",td:"border:1px solid #ddd;padding:8px;text-align:left",hr:"border:none;border-top:1px solid #ddd;margin:1em 0",img:"max-width:100%;height:auto",a:"color:#06c;text-decoration:underline",strong:"font-weight:bold",em:"font-style:italic",del:"text-decoration:line-through",ul:"margin:.5em 0;padding-left:2em",ol:"margin:.5em 0;padding-left:2em",li:"margin:.25em 0","task-item":"list-style:none","task-checkbox":"margin-right:.5em",alert:"padding:1em;margin:1em 0;border-left:4px solid #0969da;border-radius:4px;background:#ddf4ff","alert-title":"font-weight:600;margin:0 0 .4em","alert-note":"border-left-color:#0969da;background:#ddf4ff","alert-tip":"border-left-color:#1a7f37;background:#dafbe1","alert-important":"border-left-color:#8250df;background:#fbefff","alert-warning":"border-left-color:#9a6700;background:#fff8c5","alert-caution":"border-left-color:#cf222e;background:#ffebe9",sup:"font-size:.75em;vertical-align:super;line-height:0",footnotes:"margin-top:2em;font-size:.9em","footnote-backref":"text-decoration:none;margin-left:.25em"};function c(e){if(null==e||""===e)return{url:"",title:null};const t=e.match(/^(.*)\s+(?:"([^"]*)"|&quot;([^&]*?)&quot;)\s*$/);if(t)return{url:t[1].replace(/\s+$/,""),title:t[2]??t[3]};const n=e.match(/^(.*)\s+(?:'([^']*)'|&#39;([^&]*?)&#39;)\s*$/);return n?{url:n[1].replace(/\s+$/,""),title:n[2]??n[3]}:e.startsWith("&lt;")&&e.endsWith("&gt;")?{url:e.slice(4,-4),title:null}:{url:e,title:null}}function f(e){return e.replace(/[*_`~]/g,"").trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"section"}function u(e,t){const n=t.get(e)||0;return t.set(e,n+1),0===n?e:`${e}-${n}`}function p(e){let t=0,n=0;for(;n<e.length&&e.startsWith("&gt;",n);)n+=4,t++," "===e[n]&&n++;return{depth:t,content:e.slice(n)}}function d(t){const r=t.trim();return""===r||(!!/^#{1,6}\s/.test(r)||(!!e(r)||(!!/^&gt;/.test(r)||(!!/^[-*+]\s/.test(r)||(!!/^\d+\.\s/.test(r)||(!!r.startsWith("|")||!!r.startsWith(n)))))))}const $=[[/\*\*(.+?)\*\*/g,"strong"],[/__(.+?)__/g,"strong"],[/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g,"em"],[/(?<![A-Za-z0-9_])_(?![_\s])(.+?)(?<![\s_])_(?![A-Za-z0-9_])/g,"em"],[/~~(.+?)~~/g,"del"],[/`([^`\n]+)`/g,"code"]],g={NOTE:"Note",TIP:"Tip",IMPORTANT:"Important",WARNING:"Warning",CAUTION:"Caution"};function h(e,n,r){const o=e.length>0&&1===e[0].depth?e[0].content.trim().match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/i):null;let l="";const s=[],i=n("blockquote").includes("style=");for(let c=0;c<e.length;c++){const{depth:f,content:u}=e[c];if(!(f<=0)){if(o&&0===c){const e=o[1].toUpperCase(),n=e.toLowerCase();if(i){const e=a.alert,t=a["alert-"+n];l+=`<div style="${t?`${e};${t}`:e}"${r(">")}>`}else l+=`<div class="${t}alert ${t}alert-${n}"${r(">")}>`;const c=g[e];l+=i?`<p style="${a["alert-title"]}">${c}</p>`:`<p class="${t}alert-title">${c}</p>`,s.push("alert");continue}for(;s.length>f;){l+="alert"===s.pop()?"</div>":"</blockquote>"}for(;s.length<f;)0===s.length&&o?s.push("alert"):(l+=`<blockquote${n("blockquote")}${r(">")}>`,s.push("blockquote"));l+=u,c<e.length-1&&(l+="\n")}}for(;s.length>0;){l+="alert"===s.pop()?"</div>":"</blockquote>"}return l.trimEnd()}function m(e){if(0===e.length)return!1;const t=e.match(/^([ \t]+)(.*)$/);if(!t)return!1;if(t[1].replace(/\t/g," ").length<4)return!1;const n=t[2];return!(/^[-*+]\s/.test(n)||/^\d+\.\s/.test(n)||/^>/.test(n)||/^#{1,6}\s/.test(n))}function b(e){if(e.startsWith(" "))return e.slice(4);if("\t"===e[0])return e.slice(1);const t=e.match(/^[ \t]+(.*)$/);return t?t[1]:e}const _=/^(\s*)([*\-+]|\d+\.)\s+(.+)$/;function k(e){const t=e.match(/^[ \t]+(\S.*)$/);if(!t)return!1;const n=t[1];return!/^(```|~~~|>|&gt;|\||#{1,6}(\s|$)|<)/.test(n)&&!/^([-*_])\1{2,}\s*$/.test(n)}function x(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|")}function q(g,x={}){if(!g||"string"!=typeof g)return"";const{fence_plugin:q,inline_styles:w=!1,bidirectional:z=!1,lazy_linefeeds:v=!1,allow_unsafe_html:A=!1,heading_ids:C=!1,reference_links:N=!1,footnotes:E=!1}=x,W=function(e,n){return function(r,o=""){if(e){let e=n[r];return e||o?(o&&o.includes("text-align")&&e&&e.includes("text-align")&&(e=e.replace(/text-align:[^;]+;?/,"").trim(),e&&!e.endsWith(";")&&(e+=";")),` style="${o?e?`${e}${o}`:o:e}"`):""}{const e=` class="${t}${r}"`;return o?`${e} style="${o}"`:e}}}(w,a),T=new Map;function j(e){return e.replace(/[&<>"']/g,e=>i[e])}const I=z?e=>` data-qd="${j(e)}"`:()=>"";function Z(e,t=!1){if(!e)return"";if(t)return e;const n=e.trim(),r=n.toLowerCase(),o=["javascript:","vbscript:","data:"];for(const e of o)if(r.startsWith(e))return"data:"===e&&r.startsWith("data:image/")?n:"#";return n}let L=g;const O=[],S=[];L=L.replace(/^(```|~~~)([^\n]*)\n([\s\S]*?)^\1$/gm,(e,t,r,o)=>{const l=`${n}${O.length}§`,s=r?r.trim():"";return q&&q.render&&"function"==typeof q.render?O.push({lang:s,code:o.trimEnd(),custom:!0,fence:t,hasReverse:!!q.reverse}):O.push({lang:s,code:j(o.trimEnd()),custom:!1,fence:t}),l});const M=[];L=L.replace(/\\`/g,()=>{const e=`${o}${M.length}§`;return M.push("`"),e}),L=L.replace(/`([^`\n]+)`/g,(e,t)=>{const n=`§IC${S.length}§`;return S.push(j(t)),n}),L=L.replace(/\\([\\*_{}[\]()#+\-.!~|<>])/g,(e,t)=>{const n=`${o}${M.length}§`;return M.push(j(t)),n});const B=new Map,P=new Map,R=[];if(N||E){const F=L.split("\n"),J=[];let K=0;for(;K<F.length;){const Q=F[K];if(Q.includes(n))J.push(Q),K++;else{if(E){const V=Q.match(/^\[\^([^\]]+)\]:\s+([\s\S]*)$/);if(V){const X=V[1];let Y=V[2];for(;K+1<F.length;){const te=F[K+1];if(!/^[ \t]+\S/.test(te)||te.includes(n))break;Y+=" "+te.trim(),K++}const ee=X;P.has(ee)||P.set(ee,Y),K++;continue}}if(N){const ne=Q.match(/^\[([^\]]+)\]:\s+<?([^\s>]+)>?(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?\s*$/);if(ne){const re=ne[1].toLowerCase(),oe=ne[2],le=void 0!==ne[3]?ne[3]:void 0!==ne[4]?ne[4]:void 0!==ne[5]?ne[5]:null;B.has(re)||B.set(re,{url:oe,title:le}),K++;continue}}J.push(Q),K++}}L=J.join("\n")}const U=[],G=Array.isArray(A)?Object.fromEntries(A.map(e=>[e,1])):A&&"object"==typeof A?A:null;if(G&&(L=L.replace(/<!--[\s\S]*?-->/g,e=>{const t=U.length;return U.push(e),`${r}${t}§`}),L=L.replace(/<\/?([a-zA-Z][a-zA-Z0-9]*)\b[^>]*\/?>/g,(e,t)=>{if(t.toLowerCase()in G){const t=function(e){if(!/\s/.test(e.replace(/<\/?[a-zA-Z][a-zA-Z0-9]*/,"").replace(/\/?>$/,"")))return e;const t=e.match(/^(<\/?[a-zA-Z][a-zA-Z0-9]*)([\s\S]*?)(\/?>)$/);if(!t)return e;const[,n,r,o]=t,l=/([a-zA-Z_][\w\-.:]*)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+)))?/g,i=[];let a;for(;null!==(a=l.exec(r));){const e=a[1],t=void 0!==a[2]?a[2]:void 0!==a[3]?a[3]:a[4];if(!/^on/i.test(e))if(void 0===t)i.push(e);else{let n=t;e.toLowerCase()in s&&(n=Z(t)),i.push(`${e}="${n}"`)}}return n+(i.length?" "+i.join(" "):"")+o}(e),n=U.length;return U.push(t),`${r}${n}§`}return e})),!0!==A&&(L=j(L)),G&&U.forEach((e,t)=>{L=L.replace(`${r}${t}§`,e)}),L=function(e,t,n){const r=e.split("\n"),o=[];let s=0,i=!1;for(;s<r.length;){const e=r[s];if(_.test(e)){i=!0,o.push(e),s++;continue}if(i){if(k(e)){o.push(e),s++;continue}i=!1}if(!m(e)){o.push(e),s++;continue}const a=[];for(;s<r.length;){const e=r[s];if(""===e){if(s+1<r.length&&m(r[s+1])){a.push(""),s++;continue}break}if(!m(e))break;a.push(b(e)),s++}const c=a.join(l);o.push(`<pre${t("pre")}${n(" ")}><code${t("code")}>${c}</code></pre>`)}return o.join("\n")}(L,W,I),L=function(e,t,n){const r=e.split("\n"),o=[];let l=!1,s=[];for(let e=0;e<r.length;e++){const i=r[e].trim();if(i.includes("|")&&(i.startsWith("|")||/[^\\|]/.test(i)))l||(l=!0,s=[]),s.push(i);else{if(l){const e=y(s,t,n);e?o.push(e):o.push(...s),l=!1,s=[]}o.push(r[e])}}if(l&&s.length>0){const e=y(s,t,n);e?o.push(e):o.push(...s)}return o.join("\n")}(L,W,z),L=function(t,n,r,o,l,s){const i=t.split("\n"),a=[];let c=0;for(;c<i.length;){const t=i[c];if(/^\[\/\/\]: #/.test(t)){c++;continue}let $=0;for(;$<t.length&&$<7&&"#"===t[$];)$++;if($>=1&&$<=6&&" "===t[$]){const e=t.slice($+1).replace(/\s*#+\s*$/,""),i="h"+$;let p="";if(o){p=` id="${s(u(f(e),l))}"`}a.push(`<${i}${n(i)}${p}${r("#".repeat($))}>${e}</${i}>`),c++;continue}if(e(t))a.push(`<hr${n("hr")}${r(t.trim())}>`),c++;else{if(p(t).depth>0){const e=[];let t=0;for(;c<i.length;){const n=p(i[c]);if(n.depth>0)e.push(n),t=n.depth,c++;else{if(!(t>0)||d(i[c]))break;e.push({depth:t,content:i[c]}),c++}}a.push(h(e,n,r));continue}a.push(t),c++}}return a.join("\n")}(L,W,I,C,T,j),L=function(e,n,r,o){const l=e.split("\n"),s=[],i=[];let a=0,c=!1;const f=e=>e.replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[e])),u=o?e=>` data-qd="${f(e)}"`:()=>"";for(let e=0;e<l.length;e++){const o=l[e],f=o.match(_);if(f){const[,e,o,l]=f;0===i.length&&(a=e.length);const p=Math.max(0,Math.floor((e.length-a)/2)),d=/^\d+\./.test(o),$=d?"ol":"ul";let g=l,h="";const m=l.match(/^\[([x ])\]\s+(.*)$/i);if(m&&!d){const[,e,n]=m,o="x"===e.toLowerCase();g=`<input type="checkbox"${r?' style="margin-right:.5em"':` class="${t}task-checkbox"`}${o?" checked":""} disabled> ${n}`,h=r?' style="list-style:none"':` class="${t}task-item"`}for(;i.length>p+1;){const e=i.pop();s.push(`</${e.type}>`)}for(i.length===p+1&&i[p].type!==$&&s.push(`</${i.pop().type}>`);i.length<p+1;)i.push({type:$,level:i.length}),s.push(`<${$}${n($)}>`);const b=h||n("li");s.push(`<li${b}${u(o)}>${g}</li>`),c=!0}else if(c&&k(o)){let e=s[s.length-1].slice(0,-5);/( {2}|\\)$/.test(e)?e=e.replace(/( {2}|\\)$/,`<br${n("br")}>`):e+=" ",s[s.length-1]=`${e}${o.trim()}</li>`}else{for(;i.length>0;){const e=i.pop();s.push(`</${e.type}>`)}s.push(o),c=!1}}for(;i.length>0;){const e=i.pop();s.push(`</${e.type}>`)}return s.join("\n")}(L,W,w,z),L=L.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(e,t,n)=>{const{url:r,title:o}=c(n),l=Z(r,x.allow_unsafe_urls),s=o?` title="${j(o)}"`:"",i=z&&t?` data-qd-alt="${j(t)}"`:"",a=z?` data-qd-src="${j(r)}"`:"",f=z&&o?` data-qd-title="${j(o)}"`:"";return`<img${W("img")} src="${l}" alt="${t}"${s}${i}${a}${f}${I("!")}>`}),L=L.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>{const{url:r,title:o}=c(n),l=Z(r,x.allow_unsafe_urls),s=/^https?:\/\//i.test(l)?' rel="noopener noreferrer"':"",i=o?` title="${j(o)}"`:"",a=z?` data-qd-text="${j(t)}"`:"",f=z&&o?` data-qd-title="${j(o)}"`:"";return`<a${W("a")} href="${l}"${s}${i}${a}${f}${I("[")}>${t}</a>`}),L=L.replace(/(^|\s)(https?:\/\/[^\s<]+)/g,(e,t,n)=>{const{url:r,trailing:o}=function(e){let t="";const n=/[.,;:!?)]/;for(;e.length>0&&n.test(e[e.length-1]);){const n=e[e.length-1];if(")"===n&&(e.match(/\(/g)||[]).length>=(e.match(/\)/g)||[]).length)break;t=n+t,e=e.slice(0,-1)}return{url:e,trailing:t}}(n),l=Z(r,x.allow_unsafe_urls);return`${t}<a${W("a")} href="${l}" rel="noopener noreferrer">${r}</a>${o}`}),N&&B.size>0){function se(e,t,n){const r=Z(e.url,x.allow_unsafe_urls),o=/^https?:\/\//i.test(r)?' rel="noopener noreferrer"':"",l=e.title?` title="${j(e.title)}"`:"",s=z?` data-qd-ref="${j(t)}"`:"";return`<a${W("a")} href="${r}"${o}${l}${s}${I("[ref")}>${n}</a>`}L=L.replace(/\[([^\]]+)\]\[([^\]]*)\]/g,(e,t,n)=>{const r=B.get((""===n?t:n).toLowerCase());return r?se(r,n,t):e}),L=L.replace(/(?<!\])\[([^\]^[\n]+)\](?!\(|\[)/g,(e,t)=>{const n=B.get(t.toLowerCase());return n?se(n,t,t):e})}E&&P.size>0&&(L=L.replace(/\[\^([^\]]+)\]/g,(e,t)=>{if(!P.has(t))return e;let n=R.indexOf(t);-1===n?(R.push(t),n=R.length):n+=1;const r=z?` data-qd-fn="${j(t)}"`:"";return`<sup${W("sup")}${r}${I("[^")}><a href="#fn-${j(t)}" id="fnref-${j(t)}">${n}</a></sup>`}));const H=[];L=L.replace(/<[^>]+>/g,e=>(H.push(e),`%%T${H.length-1}%%`));const D=["**","__","*","_","~~"];for(let ie=0;ie<5;ie++){const[ae,ce]=$[ie];L=L.replace(ae,`<${ce}${W(ce)}${I(D[ie])}>$1</${ce}>`)}if(L=L.replace(/%%T(\d+)%%/g,(e,t)=>H[t]),L=L.replace(/\\\n/g,`<br${W("br")}>`),v){const fe=[];let ue=0;L=L.replace(/<(table|[uo]l)[^>]*>[\s\S]*?<\/\1>/g,e=>(fe[ue]=e,`§B${ue++}§`)),L=L.replace(/\n\n+/g,"§P§").replace(/(<\/(?:h[1-6]|blockquote|pre)>)\n/g,"$1§N§").replace(/(<(?:h[1-6]|blockquote|pre|hr)[^>]*>)\n/g,"$1§N§").replace(/\n(<(?:h[1-6]|blockquote|pre|hr)[^>]*>)/g,"§N§$1").replace(/\n(§B\d+§)/g,"§N§$1").replace(/(§B\d+§)\n/g,"$1§N§").replace(/\n/g,`<br${W("br")}>`).replace(/§N§/g,"\n").replace(/§P§/g,"</p><p>"),fe.forEach((e,t)=>L=L.replace(`§B${t}§`,e)),L="<p>"+L+"</p>"}else L=L.replace(/ {2}$/gm,`<br${W("br")}>`),L=L.replace(/\n\n+/g,(e,t)=>L.substring(0,t).match(/<\/(h[1-6]|blockquote|ul|ol|table|pre|hr)>$/)?"<p>":"</p><p>"),L="<p>"+L+"</p>";if([[/<p><\/p>/g,""],[/<p>(<h[1-6][^>]*>)/g,"$1"],[/(<\/h[1-6]>)<\/p>/g,"$1"],[/<p>(<blockquote[^>]*>)/g,"$1"],[/(<\/blockquote>)<\/p>/g,"$1"],[/<p>(<ul[^>]*>|<ol[^>]*>)/g,"$1"],[/(<\/ul>|<\/ol>)<\/p>/g,"$1"],[/<p>(<hr[^>]*>)<\/p>/g,"$1"],[/<p>(<table[^>]*>)/g,"$1"],[/(<\/table>)<\/p>/g,"$1"],[/<p>(<pre[^>]*>)/g,"$1"],[/(<\/pre>)<\/p>/g,"$1"],[/<p>(<div[^>]*>)/g,"$1"],[/(<\/div>)<\/p>/g,"$1"],[/<p>(<section[^>]*>)/g,"$1"],[/(<\/section>)<\/p>/g,"$1"],[new RegExp(`<p>(${n}\\d+§)</p>`,"g"),"$1"]].forEach(([e,t])=>{L=L.replace(e,t)}),L=L.replace(/(<\/(?:h[1-6]|blockquote|div|section|ul|ol|table|pre|hr)>)\n([^<])/g,"$1\n<p>$2"),E&&R.length>0){const pe=z?' data-qd="[^section"':"";let de=`<section${W("footnotes")}${pe}>`;de+=`<hr${W("hr")}>`,de+=`<ol${W("ol")}>`;for(const $e of R){const ge=P.get($e)||"";let he=!0===A?ge:j(ge);for(const[be,_e]of $)he=he.replace(be,`<${_e}${W(_e)}>$1</${_e}>`);const me=z?` data-qd-fn-id="${j($e)}"`:"";de+=`<li${W("li")} id="fn-${j($e)}"${me}>${he} <a href="#fnref-${j($e)}"${W("footnote-backref")}>↩</a></li>`}de+="</ol></section>",L+=de}return O.forEach((e,t)=>{let r;if(e.custom&&q&&q.render)if(r=q.render(e.code,e.lang),void 0===r){const t=!w&&e.lang?` class="language-${j(e.lang)}"`:"",n=w?W("code"):t,o=z&&e.lang?` data-qd-lang="${j(e.lang)}"`:"",l=z?` data-qd-fence="${j(e.fence)}"`:"";r=`<pre${W("pre")}${l}${o}><code${n}>${j(e.code)}</code></pre>`}else z&&(r=r.replace(/^<(\w+)/,`<$1 data-qd-fence="${j(e.fence)}" data-qd-lang="${j(e.lang)}" data-qd-source="${j(e.code)}"`));else{const t=!w&&e.lang?` class="language-${j(e.lang)}"`:"",n=w?W("code"):t,o=z&&e.lang?` data-qd-lang="${j(e.lang)}"`:"",l=z?` data-qd-fence="${j(e.fence)}"`:"";r=`<pre${W("pre")}${l}${o}><code${n}>${e.code}</code></pre>`}const o=`${n}${t}§`;L=L.replace(o,r)}),S.forEach((e,t)=>{const n=`§IC${t}§`;L=L.replace(n,`<code${W("code")}${I("`")}>${e}</code>`)}),M.forEach((e,t)=>{L=L.replace(`${o}${t}§`,e)}),L=L.split(l).join("\n"),L.trim()}function w(e,t){return[[/\*\*(.+?)\*\*/g,"strong"],[/__(.+?)__/g,"strong"],[/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g,"em"],[/(?<![A-Za-z0-9_])_(?![_\s])(.+?)(?<![\s_])_(?![A-Za-z0-9_])/g,"em"],[/~~(.+?)~~/g,"del"],[/`([^`\n]+)`/g,"code"]].forEach(([n,r])=>{e=e.replace(n,`<${r}${t(r)}>$1</${r}>`)}),e}function y(e,t,n){if(e.length<2)return null;let r,o,l,s=-1;for(let t=1;t<e.length;t++)if(/^\|?[\s\-:|]+\|?$/.test(e[t])&&e[t].includes("-")){s=t;break}if(-1===s)r=[e[0]],o=e.slice(1),l=x(e[0]).map(()=>"left");else{r=e.slice(0,s),o=e.slice(s+1);const t=x(e[s]);l=t.map(e=>{const t=e.trim();return t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left"})}const i=l.length,a=n?` data-qd-align="${l.join(",")}"`:"";let c=`<table${t("table")}${a}>\n`;return c+=`<thead${t("thead")}>\n`,r.forEach(e=>{c+=`<tr${t("tr")}>\n`;const n=x(e);for(let e=0;e<i;e++){const r=e<n.length?n[e]:"",o=l[e]&&"left"!==l[e]?`text-align:${l[e]}`:"",s=w(r.trim(),t);c+=`<th${t("th",o)}>${s}</th>\n`}c+="</tr>\n"}),c+="</thead>\n",o.length>0&&(c+=`<tbody${t("tbody")}>\n`,o.forEach(e=>{c+=`<tr${t("tr")}>\n`;const n=x(e);for(let e=0;e<i;e++){const r=e<n.length?n[e]:"",o=l[e]&&"left"!==l[e]?`text-align:${l[e]}`:"",s=w(r.trim(),t);c+=`<td${t("td",o)}>${s}</td>\n`}c+="</tr>\n"}),c+="</tbody>\n"),c+="</table>",c}return q.emitStyles=function(e="quikdown-",t="light"){const n=a,r={"#f4f4f4":"#2a2a2a","#f0f0f0":"#2a2a2a","#f2f2f2":"#2a2a2a","#ddd":"#3a3a3a","#06c":"#6db3f2","#ddf4ff":"#162d50","#dafbe1":"#16351d","#fbefff":"#2d1a42","#fff8c5":"#342a10","#ffebe9":"#3d1418",_textColor:"#e0e0e0"},o={_textColor:"#333"};let l="";for(const[s,i]of Object.entries(n)){let n=i;if("dark"===t&&r){for(const[e,t]of Object.entries(r))e.startsWith("_")||(n=n.replaceAll(e,t));["h1","h2","h3","h4","h5","h6","td","li","blockquote","alert","alert-title"].includes(s)&&(n+=`;color:${r._textColor}`)}else if("light"===t&&o){["h1","h2","h3","h4","h5","h6","td","li","blockquote","alert","alert-title"].includes(s)&&(n+=`;color:${o._textColor}`)}l+=`.${e}${s} { ${n} }\n`}return l},q.configure=function(e){return function(t){return q(t,e)}},q.version="1.2.22","undefined"!=typeof module&&module.exports&&(module.exports=q),"undefined"!=typeof window&&(window.quikdown=q),q}); //# sourceMappingURL=quikdown.umd.min.js.map