quikdown 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * quikdown_bd - Bidirectional Markdown Parser
3
- * @version 1.0.4
3
+ * @version 1.1.0
4
4
  * @license BSD-2-Clause
5
5
  * @copyright DeftIO 2025
6
6
  */
7
- const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function t(t){return t.replace(/[&<>"']/g,t=>e[t])}function n(e,n={}){if(!e||"string"!=typeof e)return"";const{fence_plugin:o,inline_styles:a=!1,bidirectional:l=!0}=n;l||(n.bidirectional=!1);const i=function(e,n){return function(r,o="",a=""){let l="";if(a&&(l+=` data-qd="${t(a)}"`),e){const e=n[r];(e||o)&&(l+=` style="${o?e?`${e};${o}`:o:e}"`)}else l+=` class="quikdown-${r}"`;return l}}(a,{h1:"font-size:2em;font-weight:600;margin:.67em 0;text-align:left",h2:"font-size:1.5em;font-weight:600;margin:.83em 0",h3:"font-size:1.25em;font-weight:600;margin:1em 0",h4:"font-size:1em;font-weight:600;margin:1.33em 0",h5:"font-size:.875em;font-weight:600;margin:1.67em 0",h6:"font-size:.85em;font-weight:600;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"});let c=e;const s=[],d=[];return c=c.replace(/^(```|~~~)([^\n]*)\n([\s\S]*?)^\1$/gm,(e,n,r,o)=>{const a=`§CB${s.length}§`;return s.push({fence:n,lang:r.trim(),code:t(o.trimEnd()),original:e}),a}),c=c.replace(/`([^`]+)`/g,(e,n)=>{const r=`§IC${d.length}§`;return d.push({code:t(n),original:e}),r}),c=t(c),c=c.replace(/^(#{1,6})\s+(.+?)\s*#*$/gm,(e,t,n)=>{const r=t.length;return`<h${r}${i("h"+r,"",t)}>${n}</h${r}>`}),c=c.replace(/\*\*(.+?)\*\*/g,`<strong${i("strong","","**")}>$1</strong>`),c=c.replace(/__(.+?)__/g,`<strong${i("strong","","__")}>$1</strong>`),c=c.replace(/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g,`<em${i("em","","*")}>$1</em>`),c=c.replace(/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g,`<em${i("em","","_")}>$1</em>`),c=c.replace(/~~(.+?)~~/g,`<del${i("del","","~~")}>$1</del>`),c=c.replace(/^&gt;\s+(.+)$/gm,`<blockquote${i("blockquote","",">")}>$1</blockquote>`),c=c.replace(/<\/blockquote>\n<blockquote[^>]*>/g,"\n"),c=c.replace(/^---+$/gm,`<hr${i("hr","","---")}>`),c=function(e,t){const n=e.split("\n"),r=[];let o=[];for(let e=0;e<n.length;e++){const a=n[e],l=a.match(/^(\s*)([*\-+]|\d+\.)\s+(.+)$/);if(l){const[,e,n,a]=l,i=Math.floor(e.length/2),c=/^\d+\./.test(n),s=c?"ol":"ul",d=c?"1.":n;let u=a,g="";const p=a.match(/^\[([x ])\]\s+(.*)$/i);if(p&&!c){const[,e,n]=p,r="x"===e.toLowerCase();u=`<input type="checkbox"${t("task-checkbox","","[")}${r?" checked":""}> ${n}`,g=t("task-item","","- [ ]")}for(;o.length>i+1;){const e=o.pop();r.push(`</${e.type}>`)}o.length===i&&(o.push({type:s,level:i,marker:d}),r.push(`<${s}${t(s,"",d)}>`));const $=g||t("li","",d);r.push(`<li${$}>${u}</li>`)}else{for(;o.length>0;){const e=o.pop();r.push(`</${e.type}>`)}r.push(a)}}for(;o.length>0;){const e=o.pop();r.push(`</${e.type}>`)}return r.join("\n")}(c,i),c=c.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(e,n,r)=>`<img${i("img","","!")} src="${r}" alt="${n}" data-qd-alt="${t(n)}" data-qd-src="${t(r)}">`),c=c.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,n,r)=>`<a${i("a","","[")} href="${r}" data-qd-text="${t(n)}">${n}</a>`),c=function(e,t){const n=e.split("\n"),o=[];let a=!1,l=[];for(let e=0;e<n.length;e++){const i=n[e].trim();if(i.includes("|"))a||(a=!0,l=[]),l.push(i);else{if(a){const e=r(l,t);e?o.push(e):o.push(...l),a=!1,l=[]}o.push(n[e])}}if(a&&l.length>0){const e=r(l,t);e?o.push(e):o.push(...l)}return o.join("\n")}(c,i),c=c.replace(/ $/gm,'<br data-qd=" ">'),c=c.replace(/\n\n+/g,"</p><p>"),c="<p>"+c+"</p>",c=c.replace(/<p><\/p>/g,""),c=c.replace(/<p>(<h[1-6][^>]*>)/g,"$1"),c=c.replace(/(<\/h[1-6]>)<\/p>/g,"$1"),c=c.replace(/<p>(<blockquote[^>]*>)/g,"$1"),c=c.replace(/(<\/blockquote>)<\/p>/g,"$1"),c=c.replace(/<p>(<ul[^>]*>|<ol[^>]*>)/g,"$1"),c=c.replace(/(<\/ul>|<\/ol>)<\/p>/g,"$1"),c=c.replace(/<p>(<hr[^>]*>)<\/p>/g,"$1"),c=c.replace(/<p>(<table[^>]*>)/g,"$1"),c=c.replace(/(<\/table>)<\/p>/g,"$1"),s.forEach((e,t)=>{const n=`§CB${t}§`;let r;o&&"function"==typeof o?(r=o(e.code,e.lang),void 0===r&&(r=`<pre${i("pre","",e.fence)}><code data-qd-lang="${e.lang}">${e.code}</code></pre>`)):r=`<pre${i("pre","",e.fence)} data-qd-fence="${e.fence}" data-qd-lang="${e.lang}"><code>${e.code}</code></pre>`,c=c.replace(n,r)}),d.forEach((e,t)=>{const n=`§IC${t}§`;c=c.replace(n,`<code${i("code","","`")}>${e.code}</code>`)}),c.trim()}function r(e,n){if(e.length<2)return null;let r=-1,o=[];for(let t=1;t<e.length;t++)if(/^\|?[\s\-:|]+\|?$/.test(e[t])&&e[t].includes("-")){r=t;const n=e[t].replace(/^\|/,"").replace(/\|$/,"").split("|");o=n.map(e=>{const t=e.trim();return t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left"});break}if(-1===r)return null;let a=`<table${n("table","","|")} data-qd-align="${o.join(",")}">\n`;if(r>0){a+=`<thead${n("thead","","|")}>\n<tr${n("tr","","|")}>\n`;e[0].replace(/^\|/,"").replace(/\|$/,"").split("|").forEach((e,r)=>{const l=o[r]&&"left"!==o[r]?`text-align:${o[r]}`:"";a+=`<th${n("th",l,"|")} data-qd-align="${o[r]||"left"}">${t(e.trim())}</th>\n`}),a+="</tr>\n</thead>\n"}const l=e.slice(r+1);return l.length>0&&(a+=`<tbody${n("tbody","","|")}>\n`,l.forEach(e=>{a+=`<tr${n("tr","","|")}>\n`;e.replace(/^\|/,"").replace(/\|$/,"").split("|").forEach((e,r)=>{const l=o[r]&&"left"!==o[r]?`text-align:${o[r]}`:"";a+=`<td${n("td",l,"|")} data-qd-align="${o[r]||"left"}">${t(e.trim())}</td>\n`}),a+="</tr>\n"}),a+="</tbody>\n"),a+="</table>",a}n.toMarkdown=function(e){let t;if("string"==typeof e)t=document.createElement("div"),t.innerHTML=e;else{if(!(e instanceof Element))return"";t=e}function n(e,t={}){if(e.nodeType===Node.TEXT_NODE)return e.textContent;if(e.nodeType!==Node.ELEMENT_NODE)return"";const o=e.tagName.toLowerCase(),a=e.getAttribute("data-qd"),l=window.getComputedStyle?window.getComputedStyle(e):{};let i="";for(let r of e.childNodes)i+=n(r,{parentTag:o,...t});switch(o){case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":const n=parseInt(o[1]);return`${a||"#".repeat(n)} ${i.trim()}\n\n`;case"strong":case"b":if("bold"===l.fontWeight||l.fontWeight>=700||"strong"===o||"b"===o){const e=a||"**";return`${e}${i}${e}`}return i;case"em":case"i":if("italic"===l.fontStyle||"em"===o||"i"===o){const e=a||"*";return`${e}${i}${e}`}return i;case"del":case"s":case"strike":const c=a||"~~";return`${c}${i}${c}`;case"code":if("pre"===t.parentTag)return i;const s=a||"`";return`${s}${i}${s}`;case"pre":const d=e.getAttribute("data-qd-fence")||a||"```",u=e.getAttribute("data-qd-lang")||"",g=e.querySelector("code");return`${d}${u}\n${(g?g.textContent:i).trimEnd()}\n${d}\n\n`;case"blockquote":const p=a||">";return i.trim().split("\n").map(e=>`${p} ${e}`).join("\n")+"\n\n";case"hr":return`${a||"---"}\n\n`;case"br":return`${a||" "}\n`;case"a":const $=e.getAttribute("data-qd-text")||i.trim(),f=e.getAttribute("href")||"";return $!==f||a?`[${$}](${f})`:`<${f}>`;case"img":return`${a||"!"}[${e.getAttribute("data-qd-alt")||e.getAttribute("alt")||""}](${e.getAttribute("data-qd-src")||e.getAttribute("src")||""})`;case"ul":case"ol":return r(e,"ol"===o)+"\n";case"li":case"span":default:return i;case"table":return function(e){let t="";const n=e.getAttribute("data-qd-align"),r=n?n.split(","):[],o=e.querySelector("thead");if(o){const e=o.querySelector("tr");if(e){const n=[];for(let t of e.querySelectorAll("th"))n.push(t.textContent.trim());t+="| "+n.join(" | ")+" |\n";t+="| "+n.map((e,t)=>{const n=r[t]||th.getAttribute("data-qd-align")||"left";return"center"===n?":---:":"right"===n?"---:":"---"}).join(" | ")+" |\n"}}const a=e.querySelector("tbody");if(a)for(let e of a.querySelectorAll("tr")){const n=[];for(let t of e.querySelectorAll("td"))n.push(t.textContent.trim());n.length>0&&(t+="| "+n.join(" | ")+" |\n")}return t.trim()}(e)+"\n\n";case"p":return i.trim()?i.trim()+"\n\n":"";case"div":if(e.classList&&e.classList.contains("mermaid-container")){const t=e.getAttribute("data-qd-fence")||"```",n=e.getAttribute("data-qd-lang")||"mermaid",r=e.querySelector(".mermaid-source");if(r){const e=document.createElement("div");e.innerHTML=r.innerHTML;return`${t}${n}\n${e.textContent}\n${t}\n\n`}const o=e.querySelector(".mermaid");if(o&&o.textContent.includes("graph"))return`${t}${n}\n${o.textContent.trim()}\n${t}\n\n`}if(e.classList&&e.classList.contains("mermaid")){const t=e.getAttribute("data-qd-fence")||"```";return`${t}${e.getAttribute("data-qd-lang")||"mermaid"}\n${e.textContent.trim()}\n${t}\n\n`}return i}}function r(e,t,o=0){let a="",l=1;const i=" ".repeat(o);for(let c of e.children){if("LI"!==c.tagName)continue;let e=c.getAttribute("data-qd")||(t?`${l}.`:"-");const s=c.querySelector('input[type="checkbox"]');if(s){const t=s.checked?"x":" ";e="-";let r="";for(let e of c.childNodes)e.nodeType===Node.TEXT_NODE?r+=e.textContent:e.tagName&&"INPUT"!==e.tagName&&(r+=n(e));a+=`${i}${e} [${t}] ${r.trim()}\n`}else{let t="";for(let e of c.childNodes)"UL"===e.tagName||"OL"===e.tagName?t+=r(e,"OL"===e.tagName,o+1):t+=n(e);a+=`${i}${e} ${t.trim()}\n`}l++}return a}let o=n(t);return o=o.replace(/\n{3,}/g,"\n\n"),o=o.trim(),o},n.emitStyles=function(e="quikdown-",t="light"){return""},n.configure=function(e){return function(t){return n(t,e)}},n.version="1.0.4","undefined"!=typeof module&&module.exports&&(module.exports=n),"undefined"!=typeof window&&(window.quikdown_bd=n);export{n as default};
7
+ const e="quikdown-",t="§CB",n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},r={h1:"font-size:2em;font-weight:600;margin:.67em 0;text-align:left",h2:"font-size:1.5em;font-weight:600;margin:.83em 0",h3:"font-size:1.25em;font-weight:600;margin:1em 0",h4:"font-size:1em;font-weight:600;margin:1.33em 0",h5:"font-size:.875em;font-weight:600;margin:1.67em 0",h6:"font-size:.85em;font-weight:600;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"};function o(o,a={}){if(!o||"string"!=typeof o)return"";const{fence_plugin:l,inline_styles:i=!1,bidirectional:s=!1,lazy_linefeeds:d=!1}=a,u=function(t,n){return function(r,o=""){if(t){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 t=` class="${e}${r}"`;return o?`${t} style="${o}"`:t}}}(i,r);function $(e){return e.replace(/[&<>"']/g,e=>n[e])}const f=s?e=>` data-qd="${$(e)}"`:()=>"";function g(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 p=o;const h=[],m=[];p=p.replace(/^(```|~~~)([^\n]*)\n([\s\S]*?)^\1$/gm,(e,n,r,o)=>{const a=`${t}${h.length}§`,c=r?r.trim():"";return l&&l.render&&"function"==typeof l.render?h.push({lang:c,code:o.trimEnd(),custom:!0,fence:n,hasReverse:!!l.reverse}):h.push({lang:c,code:$(o.trimEnd()),custom:!1,fence:n}),a}),p=p.replace(/`([^`]+)`/g,(e,t)=>{const n=`§IC${m.length}§`;return m.push($(t)),n}),p=$(p),p=function(e,t){const n=e.split("\n"),r=[];let o=!1,a=[];for(let e=0;e<n.length;e++){const l=n[e].trim();if(l.includes("|")&&(l.startsWith("|")||/[^\\|]/.test(l)))o||(o=!0,a=[]),a.push(l);else{if(o){const e=c(a,t);e?r.push(e):r.push(...a),o=!1,a=[]}r.push(n[e])}}if(o&&a.length>0){const e=c(a,t);e?r.push(e):r.push(...a)}return r.join("\n")}(p,u),p=p.replace(/^(#{1,6})\s+(.+?)\s*#*$/gm,(e,t,n)=>{const r=t.length;return`<h${r}${u("h"+r)}${f(t)}>${n}</h${r}>`}),p=p.replace(/^&gt;\s+(.+)$/gm,`<blockquote${u("blockquote")}>$1</blockquote>`),p=p.replace(/<\/blockquote>\n<blockquote>/g,"\n"),p=p.replace(/^---+\s*$/gm,`<hr${u("hr")}>`),p=function(t,n,r,o){const a=t.split("\n"),c=[];let l=[];const i=e=>e.replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[e])),s=o?e=>` data-qd="${i(e)}"`:()=>"";for(let t=0;t<a.length;t++){const o=a[t],i=o.match(/^(\s*)([*\-+]|\d+\.)\s+(.+)$/);if(i){const[,t,o,a]=i,d=Math.floor(t.length/2),u=/^\d+\./.test(o),$=u?"ol":"ul";let f=a,g="";const p=a.match(/^\[([x ])\]\s+(.*)$/i);if(p&&!u){const[,t,n]=p,o="x"===t.toLowerCase();f=`<input type="checkbox"${r?' style="margin-right:.5em"':` class="${e}task-checkbox"`}${o?" checked":""} disabled> ${n}`,g=r?' style="list-style:none"':` class="${e}task-item"`}for(;l.length>d+1;){const e=l.pop();c.push(`</${e.type}>`)}if(l.length===d)l.push({type:$,level:d}),c.push(`<${$}${n($)}>`);else if(l.length===d+1){const e=l[l.length-1];e.type!==$&&(c.push(`</${e.type}>`),l.pop(),l.push({type:$,level:d}),c.push(`<${$}${n($)}>`))}const h=g||n("li");c.push(`<li${h}${s(o)}>${f}</li>`)}else{for(;l.length>0;){const e=l.pop();c.push(`</${e.type}>`)}c.push(o)}}for(;l.length>0;){const e=l.pop();c.push(`</${e.type}>`)}return c.join("\n")}(p,u,i,s),p=p.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(e,t,n)=>{const r=g(n,a.allow_unsafe_urls),o=s&&t?` data-qd-alt="${$(t)}"`:"",c=s?` data-qd-src="${$(n)}"`:"";return`<img${u("img")} src="${r}" alt="${t}"${o}${c}${f("!")}>`}),p=p.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>{const r=g(n,a.allow_unsafe_urls),o=/^https?:\/\//i.test(r)?' rel="noopener noreferrer"':"",c=s?` data-qd-text="${$(t)}"`:"";return`<a${u("a")} href="${r}"${o}${c}${f("[")}>${t}</a>`}),p=p.replace(/(^|\s)(https?:\/\/[^\s<]+)/g,(e,t,n)=>{const r=g(n,a.allow_unsafe_urls);return`${t}<a${u("a")} href="${r}" rel="noopener noreferrer">${n}</a>`});if([[/\*\*(.+?)\*\*/g,"strong","**"],[/__(.+?)__/g,"strong","__"],[/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g,"em","*"],[/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g,"em","_"],[/~~(.+?)~~/g,"del","~~"]].forEach(([e,t,n])=>{p=p.replace(e,`<${t}${u(t)}${f(n)}>$1</${t}>`)}),d){const e=[];let t=0;p=p.replace(/<(table|[uo]l)[^>]*>[\s\S]*?<\/\1>/g,n=>(e[t]=n,`§B${t++}§`)),p=p.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${u("br")}>`).replace(/§N§/g,"\n").replace(/§P§/g,"</p><p>"),e.forEach((e,t)=>p=p.replace(`§B${t}§`,e)),p="<p>"+p+"</p>"}else p=p.replace(/ $/gm,`<br${u("br")}>`),p=p.replace(/\n\n+/g,(e,t)=>p.substring(0,t).match(/<\/(h[1-6]|blockquote|ul|ol|table|pre|hr)>$/)?"<p>":"</p><p>"),p="<p>"+p+"</p>";return[[/<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"],[new RegExp(`<p>(${t}\\d+§)</p>`,"g"),"$1"]].forEach(([e,t])=>{p=p.replace(e,t)}),p=p.replace(/(<\/(?:h[1-6]|blockquote|ul|ol|table|pre|hr)>)\n([^<])/g,"$1\n<p>$2"),h.forEach((e,n)=>{let r;if(e.custom&&l&&l.render)if(r=l.render(e.code,e.lang),void 0===r){const t=!i&&e.lang?` class="language-${e.lang}"`:"",n=i?u("code"):t,o=s&&e.lang?` data-qd-lang="${$(e.lang)}"`:"",a=s?` data-qd-fence="${$(e.fence)}"`:"";r=`<pre${u("pre")}${a}${o}><code${n}>${$(e.code)}</code></pre>`}else s&&(r=r.replace(/^<(\w+)/,`<$1 data-qd-fence="${$(e.fence)}" data-qd-lang="${$(e.lang)}" data-qd-source="${$(e.code)}"`));else{const t=!i&&e.lang?` class="language-${e.lang}"`:"",n=i?u("code"):t,o=s&&e.lang?` data-qd-lang="${$(e.lang)}"`:"",a=s?` data-qd-fence="${$(e.fence)}"`:"";r=`<pre${u("pre")}${a}${o}><code${n}>${e.code}</code></pre>`}const o=`${t}${n}§`;p=p.replace(o,r)}),m.forEach((e,t)=>{const n=`§IC${t}§`;p=p.replace(n,`<code${u("code")}${f("`")}>${e}</code>`)}),p.trim()}function a(e,t){return[[/\*\*(.+?)\*\*/g,"strong"],[/__(.+?)__/g,"strong"],[/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g,"em"],[/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g,"em"],[/~~(.+?)~~/g,"del"],[/`([^`]+)`/g,"code"]].forEach(([n,r])=>{e=e.replace(n,`<${r}${t(r)}>$1</${r}>`)}),e}function c(e,t){if(e.length<2)return null;let n=-1;for(let t=1;t<e.length;t++)if(/^\|?[\s\-:|]+\|?$/.test(e[t])&&e[t].includes("-")){n=t;break}if(-1===n)return null;const r=e.slice(0,n),o=e.slice(n+1),c=e[n].trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(e=>{const t=e.trim();return t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left"});let l=`<table${t("table")}>\n`;return l+=`<thead${t("thead")}>\n`,r.forEach(e=>{l+=`<tr${t("tr")}>\n`;e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").forEach((e,n)=>{const r=c[n]&&"left"!==c[n]?`text-align:${c[n]}`:"",o=a(e.trim(),t);l+=`<th${t("th",r)}>${o}</th>\n`}),l+="</tr>\n"}),l+="</thead>\n",o.length>0&&(l+=`<tbody${t("tbody")}>\n`,o.forEach(e=>{l+=`<tr${t("tr")}>\n`;e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").forEach((e,n)=>{const r=c[n]&&"left"!==c[n]?`text-align:${c[n]}`:"",o=a(e.trim(),t);l+=`<td${t("td",r)}>${o}</td>\n`}),l+="</tr>\n"}),l+="</tbody>\n"),l+="</table>",l}function l(e,t={}){return o(e,{...t,bidirectional:!0})}o.emitStyles=function(e="quikdown-",t="light"){const n=r,o={"#f4f4f4":"#2a2a2a","#f0f0f0":"#2a2a2a","#f2f2f2":"#2a2a2a","#ddd":"#3a3a3a","#06c":"#6db3f2",_textColor:"#e0e0e0"},a={_textColor:"#333"};let c="";for(const[r,l]of Object.entries(n)){let n=l;if("dark"===t&&o){for(const[e,t]of Object.entries(o))e.startsWith("_")||(n=n.replace(new RegExp(e,"g"),t));["h1","h2","h3","h4","h5","h6","td","li","blockquote"].includes(r)&&(n+=`;color:${o._textColor}`)}else if("light"===t&&a){["h1","h2","h3","h4","h5","h6","td","li","blockquote"].includes(r)&&(n+=`;color:${a._textColor}`)}c+=`.${e}${r} { ${n} }\n`}return c},o.configure=function(e){return function(t){return o(t,e)}},o.version="1.1.0","undefined"!=typeof module&&module.exports&&(module.exports=o),"undefined"!=typeof window&&(window.quikdown=o),Object.keys(o).forEach(e=>{l[e]=o[e]}),l.toMarkdown=function(e,t={}){let n;if("string"==typeof e)n=document.createElement("div"),n.innerHTML=e;else{if(!(e instanceof Element))return"";n=e}function r(e,n={}){if(e.nodeType===Node.TEXT_NODE)return e.textContent;if(e.nodeType!==Node.ELEMENT_NODE)return"";const a=e.tagName.toLowerCase(),c=e.getAttribute("data-qd");let l="";for(let t of e.childNodes)l+=r(t,{parentTag:a,...n});switch(a){case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":const n=parseInt(a[1]);return`${c||"#".repeat(n)} ${l.trim()}\n\n`;case"strong":case"b":if(!l)return"";const r=c||"**";return`${r}${l}${r}`;case"em":case"i":if(!l)return"";const i=c||"*";return`${i}${l}${i}`;case"del":case"s":case"strike":if(!l)return"";const s=c||"~~";return`${s}${l}${s}`;case"code":if(!l)return"";const d=c||"`";return`${d}${l}${d}`;case"pre":const u=e.getAttribute("data-qd-fence")||c||"```",$=e.getAttribute("data-qd-lang")||"";if(t.fence_plugin&&t.fence_plugin.reverse&&$)try{const n=t.fence_plugin.reverse(e);if(n&&n.content){const e=n.fence||u;return`${e}${n.lang||$}\n${n.content}\n${e}\n\n`}}catch(e){console.warn("Fence reverse handler error:",e)}const f=e.getAttribute("data-qd-source");if(f)return`${u}${$}\n${f}\n${u}\n\n`;const g=e.querySelector("code");return`${u}${$}\n${(g?g.textContent:l).trimEnd()}\n${u}\n\n`;case"blockquote":const p=c||">";return l.trim().split("\n").map(e=>`${p} ${e}`).join("\n")+"\n\n";case"hr":return`${c||"---"}\n\n`;case"br":return`${c||" "}\n`;case"a":const h=e.getAttribute("data-qd-text")||l.trim(),m=e.getAttribute("href")||"";return h!==m||c?`[${h}](${m})`:`<${m}>`;case"img":return`${c||"!"}[${e.getAttribute("data-qd-alt")||e.getAttribute("alt")||""}](${e.getAttribute("data-qd-src")||e.getAttribute("src")||""})`;case"ul":case"ol":return o(e,"ol"===a)+"\n";case"li":case"span":default:return l;case"table":return function(e){let t="";const n=e.getAttribute("data-qd-align"),r=n?n.split(","):[],o=e.querySelector("thead");if(o){const e=o.querySelector("tr");if(e){const n=[];for(let t of e.querySelectorAll("th"))n.push(t.textContent.trim());t+="| "+n.join(" | ")+" |\n";t+="| "+n.map((e,t)=>{const n=r[t]||"left";return"center"===n?":---:":"right"===n?"---:":"---"}).join(" | ")+" |\n"}}const a=e.querySelector("tbody");if(a)for(let e of a.querySelectorAll("tr")){const n=[];for(let t of e.querySelectorAll("td"))n.push(t.textContent.trim());n.length>0&&(t+="| "+n.join(" | ")+" |\n")}return t.trim()}(e)+"\n\n";case"p":if(l.trim()){const e=l.split("\n");let t=l.trim();if(e.length>1){let n=0;for(let t=e.length-1;t>=0&&""===e[t].trim();t--)n++;if(n>0)return t+="\n ",t+"\n"}return t+"\n\n"}return"";case"div":const b=e.getAttribute("data-qd-lang"),q=e.getAttribute("data-qd-fence");if(b&&t.fence_plugin&&t.fence_plugin.reverse)try{const n=t.fence_plugin.reverse(e);if(n&&n.content){const e=n.fence||q||"```";return`${e}${n.lang||b}\n${n.content}\n${e}\n\n`}}catch(e){console.warn("Fence reverse handler error:",e)}const x=e.getAttribute("data-qd-source");if(x&&q)return`${q}${b||""}\n${x}\n${q}\n\n`;if(e.classList&&e.classList.contains("mermaid-container")){const t=e.getAttribute("data-qd-fence")||"```",n=e.getAttribute("data-qd-lang")||"mermaid",r=e.getAttribute("data-qd-source");if(r){const e=document.createElement("textarea");e.innerHTML=r;return`${t}${n}\n${e.value}\n${t}\n\n`}const o=e.querySelector("pre.mermaid");if(o){const e=o.getAttribute("data-qd-source");if(e){const r=document.createElement("textarea");r.innerHTML=e;return`${t}${n}\n${r.value}\n${t}\n\n`}}const a=e.querySelector(".mermaid-source");if(a){const e=document.createElement("div");e.innerHTML=a.innerHTML;return`${t}${n}\n${e.textContent}\n${t}\n\n`}const c=e.querySelector(".mermaid");if(c&&c.textContent.includes("graph"))return`${t}${n}\n${c.textContent.trim()}\n${t}\n\n`}if(e.classList&&e.classList.contains("mermaid")){const t=e.getAttribute("data-qd-fence")||"```";return`${t}${e.getAttribute("data-qd-lang")||"mermaid"}\n${e.textContent.trim()}\n${t}\n\n`}return l}}function o(e,t,n=0){let a="",c=1;const l=" ".repeat(n);for(let i of e.children){if("LI"!==i.tagName)continue;let e=i.getAttribute("data-qd")||(t?`${c}.`:"-");const s=i.querySelector('input[type="checkbox"]');if(s){const t=s.checked?"x":" ";e="-";let n="";for(let e of i.childNodes)e.nodeType===Node.TEXT_NODE?n+=e.textContent:e.tagName&&"INPUT"!==e.tagName&&(n+=r(e));a+=`${l}${e} [${t}] ${n.trim()}\n`}else{let t="";for(let e of i.childNodes)"UL"===e.tagName||"OL"===e.tagName?t+=o(e,"OL"===e.tagName,n+1):t+=r(e);a+=`${l}${e} ${t.trim()}\n`}c++}return a}let a=r(n);return a=a.replace(/\n{3,}/g,"\n\n"),a=a.trim(),a},l.configure=function(e){return function(t){return l(t,e)}},"undefined"!=typeof module&&module.exports&&(module.exports=l),"undefined"!=typeof window&&(window.quikdown_bd=l);export{l as default};
8
8
  //# sourceMappingURL=quikdown_bd.esm.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"quikdown_bd.esm.min.js","sources":["../src/quikdown_bd.js"],"sourcesContent":["/**\n * quikdown_bd - Bidirectional markdown/HTML converter\n * Standalone version with round-trip conversion support\n * \n * Uses data-qd attributes to preserve original markdown syntax\n * Enables HTML→Markdown conversion for quikdown-generated HTML\n */\n\n// Version - uses same version as core quikdown\nconst VERSION = '__QUIKDOWN_VERSION__';\n\n// Helper to escape HTML (same as core)\nconst ESC_MAP = {'&':'&amp;','<':'&lt;','>':'&gt;','\"':'&quot;',\"'\":'&#39;'};\nfunction escapeHtml(text) {\n return text.replace(/[&<>\"']/g, m => ESC_MAP[m]);\n}\n\n// Modified getAttr that adds data-qd attributes\nfunction createGetAttrBD(inline_styles, styles) {\n return function(tag, additionalStyle = '', sourceMarker = '') {\n let attrs = '';\n \n // Add data-qd attribute if source marker provided\n if (sourceMarker) {\n attrs += ` data-qd=\"${escapeHtml(sourceMarker)}\"`;\n }\n \n // Add style or class\n if (inline_styles) {\n const style = styles[tag];\n if (style || additionalStyle) {\n const fullStyle = additionalStyle ? (style ? `${style};${additionalStyle}` : additionalStyle) : style;\n attrs += ` style=\"${fullStyle}\"`;\n }\n } else {\n attrs += ` class=\"quikdown-${tag}\"`;\n }\n \n return attrs;\n };\n}\n\n/**\n * Enhanced markdown parser with bidirectional support\n * Wraps the core parser and adds data-qd attributes\n */\nfunction quikdown_bd(markdown, options = {}) {\n if (!markdown || typeof markdown !== 'string') {\n return '';\n }\n \n const { fence_plugin, inline_styles = false, bidirectional = true } = options;\n \n // If not bidirectional mode, process without data-qd attributes\n if (!bidirectional) {\n // Process without bidirectional tracking\n options.bidirectional = false;\n }\n \n // For bidirectional, we need to manually process with source tracking\n // This is a custom implementation that adds data-qd attributes\n \n const QUIKDOWN_STYLES = {\n h1: 'font-size:2em;font-weight:600;margin:.67em 0;text-align:left',\n h2: 'font-size:1.5em;font-weight:600;margin:.83em 0',\n h3: 'font-size:1.25em;font-weight:600;margin:1em 0',\n h4: 'font-size:1em;font-weight:600;margin:1.33em 0',\n h5: 'font-size:.875em;font-weight:600;margin:1.67em 0',\n h6: 'font-size:.85em;font-weight:600;margin:2em 0',\n pre: 'background:#f4f4f4;padding:10px;border-radius:4px;overflow-x:auto;margin:1em 0',\n code: 'background:#f0f0f0;padding:2px 4px;border-radius:3px;font-family:monospace',\n blockquote: 'border-left:4px solid #ddd;margin-left:0;padding-left:1em',\n table: 'border-collapse:collapse;width:100%;margin:1em 0',\n th: 'border:1px solid #ddd;padding:8px;background-color:#f2f2f2;font-weight:bold;text-align:left',\n td: 'border:1px solid #ddd;padding:8px;text-align:left',\n hr: 'border:none;border-top:1px solid #ddd;margin:1em 0',\n img: 'max-width:100%;height:auto',\n a: 'color:#06c;text-decoration:underline',\n strong: 'font-weight:bold',\n em: 'font-style:italic',\n del: 'text-decoration:line-through',\n ul: 'margin:.5em 0;padding-left:2em',\n ol: 'margin:.5em 0;padding-left:2em',\n li: 'margin:.25em 0',\n 'task-item': 'list-style:none',\n 'task-checkbox': 'margin-right:.5em'\n };\n \n const getAttr = createGetAttrBD(inline_styles, QUIKDOWN_STYLES);\n \n // Process markdown with source tracking\n let html = markdown;\n \n // Phase 1: Extract and protect code blocks\n const codeBlocks = [];\n const inlineCodes = [];\n \n // Extract fenced code blocks\n html = html.replace(/^(```|~~~)([^\\n]*)\\n([\\s\\S]*?)^\\1$/gm, (match, fence, lang, code) => {\n const placeholder = `§CB${codeBlocks.length}§`;\n codeBlocks.push({\n fence,\n lang: lang.trim(),\n code: escapeHtml(code.trimEnd()),\n original: match\n });\n return placeholder;\n });\n \n // Extract inline code\n html = html.replace(/`([^`]+)`/g, (match, code) => {\n const placeholder = `§IC${inlineCodes.length}§`;\n inlineCodes.push({\n code: escapeHtml(code),\n original: match\n });\n return placeholder;\n });\n \n // Escape HTML\n html = escapeHtml(html);\n \n // Process headings with source tracking\n html = html.replace(/^(#{1,6})\\s+(.+?)\\s*#*$/gm, (match, hashes, content) => {\n const level = hashes.length;\n const sourceMarker = hashes;\n return `<h${level}${getAttr('h' + level, '', sourceMarker)}>${content}</h${level}>`;\n });\n \n // Process bold/italic/strikethrough with source tracking\n html = html.replace(/\\*\\*(.+?)\\*\\*/g, `<strong${getAttr('strong', '', '**')}>$1</strong>`);\n html = html.replace(/__(.+?)__/g, `<strong${getAttr('strong', '', '__')}>$1</strong>`);\n html = html.replace(/(?<!\\*)\\*(?!\\*)(.+?)(?<!\\*)\\*(?!\\*)/g, `<em${getAttr('em', '', '*')}>$1</em>`);\n html = html.replace(/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g, `<em${getAttr('em', '', '_')}>$1</em>`);\n html = html.replace(/~~(.+?)~~/g, `<del${getAttr('del', '', '~~')}>$1</del>`);\n \n // Process blockquotes\n html = html.replace(/^&gt;\\s+(.+)$/gm, `<blockquote${getAttr('blockquote', '', '>')}>$1</blockquote>`);\n html = html.replace(/<\\/blockquote>\\n<blockquote[^>]*>/g, '\\n');\n \n // Process horizontal rules\n html = html.replace(/^---+$/gm, `<hr${getAttr('hr', '', '---')}>`);\n \n // Process lists (simplified for now)\n html = processListsBD(html, getAttr, inline_styles);\n \n // Process links and images\n html = html.replace(/!\\[([^\\]]*)\\]\\(([^)]+)\\)/g, (match, alt, src) => {\n return `<img${getAttr('img', '', '!')} src=\"${src}\" alt=\"${alt}\" data-qd-alt=\"${escapeHtml(alt)}\" data-qd-src=\"${escapeHtml(src)}\">`;\n });\n \n html = html.replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, (match, text, href) => {\n return `<a${getAttr('a', '', '[')} href=\"${href}\" data-qd-text=\"${escapeHtml(text)}\">${text}</a>`;\n });\n \n // Process tables\n html = processTablesBD(html, getAttr);\n \n // Line breaks\n html = html.replace(/ $/gm, '<br data-qd=\" \">');\n \n // Paragraphs\n html = html.replace(/\\n\\n+/g, '</p><p>');\n html = '<p>' + html + '</p>';\n \n // Clean up empty paragraphs and unwrap block elements\n html = html.replace(/<p><\\/p>/g, '');\n html = html.replace(/<p>(<h[1-6][^>]*>)/g, '$1');\n html = html.replace(/(<\\/h[1-6]>)<\\/p>/g, '$1');\n html = html.replace(/<p>(<blockquote[^>]*>)/g, '$1');\n html = html.replace(/(<\\/blockquote>)<\\/p>/g, '$1');\n html = html.replace(/<p>(<ul[^>]*>|<ol[^>]*>)/g, '$1');\n html = html.replace(/(<\\/ul>|<\\/ol>)<\\/p>/g, '$1');\n html = html.replace(/<p>(<hr[^>]*>)<\\/p>/g, '$1');\n html = html.replace(/<p>(<table[^>]*>)/g, '$1');\n html = html.replace(/(<\\/table>)<\\/p>/g, '$1');\n \n // Restore code blocks\n codeBlocks.forEach((block, i) => {\n const placeholder = `§CB${i}§`;\n let replacement;\n \n if (fence_plugin && typeof fence_plugin === 'function') {\n replacement = fence_plugin(block.code, block.lang);\n if (replacement === undefined) {\n replacement = `<pre${getAttr('pre', '', block.fence)}><code data-qd-lang=\"${block.lang}\">${block.code}</code></pre>`;\n }\n } else {\n replacement = `<pre${getAttr('pre', '', block.fence)} data-qd-fence=\"${block.fence}\" data-qd-lang=\"${block.lang}\"><code>${block.code}</code></pre>`;\n }\n \n html = html.replace(placeholder, replacement);\n });\n \n // Restore inline codes\n inlineCodes.forEach((item, i) => {\n const placeholder = `§IC${i}§`;\n html = html.replace(placeholder, `<code${getAttr('code', '', '`')}>${item.code}</code>`);\n });\n \n return html.trim();\n}\n\n// Process lists with source tracking\nfunction processListsBD(text, getAttr, inline_styles) {\n const lines = text.split('\\n');\n const result = [];\n let listStack = [];\n \n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n const match = line.match(/^(\\s*)([*\\-+]|\\d+\\.)\\s+(.+)$/);\n \n if (match) {\n const [, indent, marker, content] = match;\n const level = Math.floor(indent.length / 2);\n const isOrdered = /^\\d+\\./.test(marker);\n const listType = isOrdered ? 'ol' : 'ul';\n const sourceMarker = isOrdered ? '1.' : marker;\n \n // Handle task lists\n let listItemContent = content;\n let taskAttrs = '';\n const taskMatch = content.match(/^\\[([x ])\\]\\s+(.*)$/i);\n if (taskMatch && !isOrdered) {\n const [, checked, taskContent] = taskMatch;\n const isChecked = checked.toLowerCase() === 'x';\n listItemContent = `<input type=\"checkbox\"${getAttr('task-checkbox', '', '[')}${isChecked ? ' checked' : ''}> ${taskContent}`;\n taskAttrs = getAttr('task-item', '', '- [ ]');\n }\n \n // Close deeper levels\n while (listStack.length > level + 1) {\n const list = listStack.pop();\n result.push(`</${list.type}>`);\n }\n \n // Open new level if needed\n if (listStack.length === level) {\n listStack.push({ type: listType, level, marker: sourceMarker });\n result.push(`<${listType}${getAttr(listType, '', sourceMarker)}>`);\n }\n \n const liAttr = taskAttrs || getAttr('li', '', sourceMarker);\n result.push(`<li${liAttr}>${listItemContent}</li>`);\n } else {\n // Close all lists\n while (listStack.length > 0) {\n const list = listStack.pop();\n result.push(`</${list.type}>`);\n }\n result.push(line);\n }\n }\n \n // Close remaining lists\n while (listStack.length > 0) {\n const list = listStack.pop();\n result.push(`</${list.type}>`);\n }\n \n return result.join('\\n');\n}\n\n// Process tables with source tracking\nfunction processTablesBD(text, getAttr) {\n const lines = text.split('\\n');\n const result = [];\n let inTable = false;\n let tableLines = [];\n \n for (let i = 0; i < lines.length; i++) {\n const line = lines[i].trim();\n \n if (line.includes('|')) {\n if (!inTable) {\n inTable = true;\n tableLines = [];\n }\n tableLines.push(line);\n } else {\n if (inTable) {\n const tableHtml = buildTableBD(tableLines, getAttr);\n if (tableHtml) {\n result.push(tableHtml);\n } else {\n result.push(...tableLines);\n }\n inTable = false;\n tableLines = [];\n }\n result.push(lines[i]);\n }\n }\n \n if (inTable && tableLines.length > 0) {\n const tableHtml = buildTableBD(tableLines, getAttr);\n if (tableHtml) {\n result.push(tableHtml);\n } else {\n result.push(...tableLines);\n }\n }\n \n return result.join('\\n');\n}\n\n// Build table with source tracking\nfunction buildTableBD(lines, getAttr) {\n if (lines.length < 2) return null;\n \n // Find separator\n let separatorIndex = -1;\n let alignments = [];\n \n for (let i = 1; i < lines.length; i++) {\n if (/^\\|?[\\s\\-:|]+\\|?$/.test(lines[i]) && lines[i].includes('-')) {\n separatorIndex = i;\n const cells = lines[i].replace(/^\\|/, '').replace(/\\|$/, '').split('|');\n alignments = cells.map(cell => {\n const trimmed = cell.trim();\n if (trimmed.startsWith(':') && trimmed.endsWith(':')) return 'center';\n if (trimmed.endsWith(':')) return 'right';\n return 'left';\n });\n break;\n }\n }\n \n if (separatorIndex === -1) return null;\n \n let html = `<table${getAttr('table', '', '|')} data-qd-align=\"${alignments.join(',')}\">\\n`;\n \n // Headers\n if (separatorIndex > 0) {\n html += `<thead${getAttr('thead', '', '|')}>\\n<tr${getAttr('tr', '', '|')}>\\n`;\n const cells = lines[0].replace(/^\\|/, '').replace(/\\|$/, '').split('|');\n cells.forEach((cell, i) => {\n const align = alignments[i] && alignments[i] !== 'left' ? `text-align:${alignments[i]}` : '';\n html += `<th${getAttr('th', align, '|')} data-qd-align=\"${alignments[i] || 'left'}\">${escapeHtml(cell.trim())}</th>\\n`;\n });\n html += '</tr>\\n</thead>\\n';\n }\n \n // Body\n const bodyLines = lines.slice(separatorIndex + 1);\n if (bodyLines.length > 0) {\n html += `<tbody${getAttr('tbody', '', '|')}>\\n`;\n bodyLines.forEach(line => {\n html += `<tr${getAttr('tr', '', '|')}>\\n`;\n const cells = line.replace(/^\\|/, '').replace(/\\|$/, '').split('|');\n cells.forEach((cell, i) => {\n const align = alignments[i] && alignments[i] !== 'left' ? `text-align:${alignments[i]}` : '';\n html += `<td${getAttr('td', align, '|')} data-qd-align=\"${alignments[i] || 'left'}\">${escapeHtml(cell.trim())}</td>\\n`;\n });\n html += '</tr>\\n';\n });\n html += '</tbody>\\n';\n }\n \n html += '</table>';\n return html;\n}\n\n/**\n * Convert HTML back to Markdown by walking the DOM tree\n * Uses data-qd attributes when available, falls back to canonical forms\n * Assumes browser environment with DOM API available\n */\nquikdown_bd.toMarkdown = function(htmlOrElement) {\n // Accept either HTML string or DOM element\n let container;\n if (typeof htmlOrElement === 'string') {\n container = document.createElement('div');\n container.innerHTML = htmlOrElement;\n } else if (htmlOrElement instanceof Element) {\n container = htmlOrElement;\n } else {\n return '';\n }\n \n // Walk the DOM tree and reconstruct markdown\n function walkNode(node, parentContext = {}) {\n if (node.nodeType === Node.TEXT_NODE) {\n // Return text content, preserving whitespace where needed\n return node.textContent;\n }\n \n if (node.nodeType !== Node.ELEMENT_NODE) {\n return '';\n }\n \n const tag = node.tagName.toLowerCase();\n const dataQd = node.getAttribute('data-qd');\n const styles = window.getComputedStyle ? window.getComputedStyle(node) : {};\n \n // Process children with context\n let childContent = '';\n for (let child of node.childNodes) {\n childContent += walkNode(child, { parentTag: tag, ...parentContext });\n }\n \n // Determine markdown based on element and attributes\n switch (tag) {\n case 'h1':\n case 'h2':\n case 'h3':\n case 'h4':\n case 'h5':\n case 'h6':\n const level = parseInt(tag[1]);\n const prefix = dataQd || '#'.repeat(level);\n return `${prefix} ${childContent.trim()}\\n\\n`;\n \n case 'strong':\n case 'b':\n // Check if it's bold through style too\n if (styles.fontWeight === 'bold' || styles.fontWeight >= 700 || tag === 'strong' || tag === 'b') {\n const boldMarker = dataQd || '**';\n return `${boldMarker}${childContent}${boldMarker}`;\n }\n return childContent;\n \n case 'em':\n case 'i':\n // Check for italic through style\n if (styles.fontStyle === 'italic' || tag === 'em' || tag === 'i') {\n const emMarker = dataQd || '*';\n return `${emMarker}${childContent}${emMarker}`;\n }\n return childContent;\n \n case 'del':\n case 's':\n case 'strike':\n const delMarker = dataQd || '~~';\n return `${delMarker}${childContent}${delMarker}`;\n \n case 'code':\n // Skip if inside pre (handled by pre)\n if (parentContext.parentTag === 'pre') {\n return childContent;\n }\n const codeMarker = dataQd || '`';\n return `${codeMarker}${childContent}${codeMarker}`;\n \n case 'pre':\n const fence = node.getAttribute('data-qd-fence') || dataQd || '```';\n const lang = node.getAttribute('data-qd-lang') || '';\n // Look for code element child\n const codeEl = node.querySelector('code');\n const codeContent = codeEl ? codeEl.textContent : childContent;\n return `${fence}${lang}\\n${codeContent.trimEnd()}\\n${fence}\\n\\n`;\n \n case 'blockquote':\n const quoteMarker = dataQd || '>';\n const lines = childContent.trim().split('\\n');\n return lines.map(line => `${quoteMarker} ${line}`).join('\\n') + '\\n\\n';\n \n case 'hr':\n const hrMarker = dataQd || '---';\n return `${hrMarker}\\n\\n`;\n \n case 'br':\n const brMarker = dataQd || ' ';\n return `${brMarker}\\n`;\n \n case 'a':\n const linkText = node.getAttribute('data-qd-text') || childContent.trim();\n const href = node.getAttribute('href') || '';\n // Check for autolinks\n if (linkText === href && !dataQd) {\n return `<${href}>`;\n }\n return `[${linkText}](${href})`;\n \n case 'img':\n const alt = node.getAttribute('data-qd-alt') || node.getAttribute('alt') || '';\n const src = node.getAttribute('data-qd-src') || node.getAttribute('src') || '';\n const imgMarker = dataQd || '!';\n return `${imgMarker}[${alt}](${src})`;\n \n case 'ul':\n case 'ol':\n return walkList(node, tag === 'ol') + '\\n';\n \n case 'li':\n // Handled by list processor\n return childContent;\n \n case 'table':\n return walkTable(node) + '\\n\\n';\n \n case 'p':\n // Check if it's actually a paragraph or just a wrapper\n if (childContent.trim()) {\n return childContent.trim() + '\\n\\n';\n }\n return '';\n \n case 'div':\n // Check if it's a mermaid container\n if (node.classList && node.classList.contains('mermaid-container')) {\n const fence = node.getAttribute('data-qd-fence') || '```';\n const lang = node.getAttribute('data-qd-lang') || 'mermaid';\n // Look for the source element\n const sourceElement = node.querySelector('.mermaid-source');\n if (sourceElement) {\n // Decode HTML entities\n const temp = document.createElement('div');\n temp.innerHTML = sourceElement.innerHTML;\n const code = temp.textContent;\n return `${fence}${lang}\\n${code}\\n${fence}\\n\\n`;\n }\n // Fallback: try to extract from the mermaid element\n const mermaidElement = node.querySelector('.mermaid');\n if (mermaidElement && mermaidElement.textContent.includes('graph')) {\n return `${fence}${lang}\\n${mermaidElement.textContent.trim()}\\n${fence}\\n\\n`;\n }\n }\n // Check if it's a standalone mermaid diagram (legacy)\n if (node.classList && node.classList.contains('mermaid')) {\n const fence = node.getAttribute('data-qd-fence') || '```';\n const lang = node.getAttribute('data-qd-lang') || 'mermaid';\n const code = node.textContent.trim();\n return `${fence}${lang}\\n${code}\\n${fence}\\n\\n`;\n }\n // Pass through other divs\n return childContent;\n \n case 'span':\n // Pass through container elements\n return childContent;\n \n default:\n return childContent;\n }\n }\n \n // Walk list elements\n function walkList(listNode, isOrdered, depth = 0) {\n let result = '';\n let index = 1;\n const indent = ' '.repeat(depth);\n \n for (let child of listNode.children) {\n if (child.tagName !== 'LI') continue;\n \n const dataQd = child.getAttribute('data-qd');\n let marker = dataQd || (isOrdered ? `${index}.` : '-');\n \n // Check for task list checkbox\n const checkbox = child.querySelector('input[type=\"checkbox\"]');\n if (checkbox) {\n const checked = checkbox.checked ? 'x' : ' ';\n marker = '-';\n // Get text without the checkbox\n let text = '';\n for (let node of child.childNodes) {\n if (node.nodeType === Node.TEXT_NODE) {\n text += node.textContent;\n } else if (node.tagName && node.tagName !== 'INPUT') {\n text += walkNode(node);\n }\n }\n result += `${indent}${marker} [${checked}] ${text.trim()}\\n`;\n } else {\n // Check for nested lists\n let hasNestedList = false;\n let itemContent = '';\n \n for (let node of child.childNodes) {\n if (node.tagName === 'UL' || node.tagName === 'OL') {\n hasNestedList = true;\n itemContent += walkList(node, node.tagName === 'OL', depth + 1);\n } else {\n itemContent += walkNode(node);\n }\n }\n \n result += `${indent}${marker} ${itemContent.trim()}\\n`;\n }\n \n index++;\n }\n \n return result;\n }\n \n // Walk table elements\n function walkTable(table) {\n let result = '';\n const alignData = table.getAttribute('data-qd-align');\n const alignments = alignData ? alignData.split(',') : [];\n \n // Process header\n const thead = table.querySelector('thead');\n if (thead) {\n const headerRow = thead.querySelector('tr');\n if (headerRow) {\n const headers = [];\n for (let th of headerRow.querySelectorAll('th')) {\n headers.push(th.textContent.trim());\n }\n result += '| ' + headers.join(' | ') + ' |\\n';\n \n // Add separator with alignment\n const separators = headers.map((_, i) => {\n const align = alignments[i] || th.getAttribute('data-qd-align') || 'left';\n if (align === 'center') return ':---:';\n if (align === 'right') return '---:';\n return '---';\n });\n result += '| ' + separators.join(' | ') + ' |\\n';\n }\n }\n \n // Process body\n const tbody = table.querySelector('tbody');\n if (tbody) {\n for (let row of tbody.querySelectorAll('tr')) {\n const cells = [];\n for (let td of row.querySelectorAll('td')) {\n cells.push(td.textContent.trim());\n }\n if (cells.length > 0) {\n result += '| ' + cells.join(' | ') + ' |\\n';\n }\n }\n }\n \n return result.trim();\n }\n \n // Process the DOM tree\n let markdown = walkNode(container);\n \n // Clean up\n markdown = markdown.replace(/\\n{3,}/g, '\\n\\n'); // Remove excessive newlines\n markdown = markdown.trim();\n \n return markdown;\n};\n\n// Add emitStyles method (same as core)\nquikdown_bd.emitStyles = function(prefix = 'quikdown-', theme = 'light') {\n // This would generate CSS based on the styles\n // For now, returning empty string as placeholder\n // In production, this would generate the full CSS\n return '';\n};\n\n// Configure method\nquikdown_bd.configure = function(options) {\n return function(markdown) {\n return quikdown_bd(markdown, options);\n };\n};\n\n// Version property\nquikdown_bd.version = VERSION;\n\n// Export for both module and browser\nif (typeof module !== 'undefined' && module.exports) {\n module.exports = quikdown_bd;\n}\n\nif (typeof window !== 'undefined') {\n window.quikdown_bd = quikdown_bd;\n}\n\nexport default quikdown_bd;"],"names":["ESC_MAP","escapeHtml","text","replace","m","quikdown_bd","markdown","options","fence_plugin","inline_styles","bidirectional","getAttr","styles","tag","additionalStyle","sourceMarker","attrs","style","createGetAttrBD","h1","h2","h3","h4","h5","h6","pre","code","blockquote","table","th","td","hr","img","a","strong","em","del","ul","ol","li","html","codeBlocks","inlineCodes","match","fence","lang","placeholder","length","push","trim","trimEnd","original","hashes","content","level","lines","split","result","listStack","i","line","indent","marker","Math","floor","isOrdered","test","listType","listItemContent","taskAttrs","taskMatch","checked","taskContent","isChecked","toLowerCase","list","pop","type","liAttr","join","processListsBD","alt","src","href","inTable","tableLines","includes","tableHtml","buildTableBD","processTablesBD","forEach","block","replacement","undefined","item","separatorIndex","alignments","cells","map","cell","trimmed","startsWith","endsWith","align","bodyLines","slice","toMarkdown","htmlOrElement","container","document","createElement","innerHTML","Element","walkNode","node","parentContext","nodeType","Node","TEXT_NODE","textContent","ELEMENT_NODE","tagName","dataQd","getAttribute","window","getComputedStyle","childContent","child","childNodes","parentTag","parseInt","repeat","fontWeight","boldMarker","fontStyle","emMarker","delMarker","codeMarker","codeEl","querySelector","quoteMarker","linkText","walkList","alignData","thead","headerRow","headers","querySelectorAll","_","tbody","row","walkTable","classList","contains","sourceElement","temp","mermaidElement","listNode","depth","index","children","checkbox","itemContent","emitStyles","prefix","theme","configure","version","module","exports"],"mappings":";;;;;;AASA,MAGMA,EAAU,CAAC,IAAI,QAAQ,IAAI,OAAO,IAAI,OAAO,IAAI,SAAS,IAAI,SACpE,SAASC,EAAWC,GAChB,OAAOA,EAAKC,QAAQ,WAAYC,GAAKJ,EAAQI,GACjD,CA+BA,SAASC,EAAYC,EAAUC,EAAU,IACrC,IAAKD,GAAgC,iBAAbA,EACpB,MAAO,GAGX,MAAME,aAAEA,EAAYC,cAAEA,GAAgB,EAAKC,cAAEA,GAAgB,GAASH,EAGjEG,IAEDH,EAAQG,eAAgB,GAM5B,MA0BMC,EAtEV,SAAyBF,EAAeG,GACpC,OAAO,SAASC,EAAKC,EAAkB,GAAIC,EAAe,IACtD,IAAIC,EAAQ,GAQZ,GALID,IACAC,GAAS,aAAaf,EAAWc,OAIjCN,EAAe,CACf,MAAMQ,EAAQL,EAAOC,IACjBI,GAASH,KAETE,GAAS,WADSF,EAAmBG,EAAQ,GAAGA,KAASH,IAAoBA,EAAmBG,KAGxG,MACID,GAAS,oBAAoBH,KAGjC,OAAOG,CACX,CACJ,CAgDoBE,CAAgBT,EA1BR,CACpBU,GAAI,+DACJC,GAAI,iDACJC,GAAI,gDACJC,GAAI,gDACJC,GAAI,mDACJC,GAAI,+CACJC,IAAK,iFACLC,KAAM,6EACNC,WAAY,4DACZC,MAAO,mDACPC,GAAI,8FACJC,GAAI,oDACJC,GAAI,qDACJC,IAAK,6BAC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,EAAYiK,UAAY,SAAS/J,GAC7B,OAAO,SAASD,GACZ,OAAOD,EAAYC,EAAUC,EACjC,CACJ,EAGAF,EAAYkK,QA3oBI,QA8oBM,oBAAXC,QAA0BA,OAAOC,UACxCD,OAAOC,QAAUpK,GAGC,oBAAXuH,SACPA,OAAOvH,YAAcA"}
1
+ {"version":3,"file":"quikdown_bd.esm.min.js","sources":["../src/quikdown.js","../src/quikdown_bd.js"],"sourcesContent":["/**\n * quikdown - A minimal markdown parser optimized for chat/LLM output\n * Supports tables, code blocks, lists, and common formatting\n * @param {string} markdown - The markdown source text\n * @param {Object} options - Optional configuration object\n * @param {Function} options.fence_plugin - Custom renderer for fenced code blocks\n * (content, fence_string) => html string\n * @param {boolean} options.inline_styles - If true, uses inline styles instead of classes\n * @param {boolean} options.bidirectional - If true, adds data-qd attributes for source tracking\n * @param {boolean} options.lazy_linefeeds - If true, single newlines become <br> tags\n * @returns {string} - The rendered HTML\n */\n\n// Version will be injected at build time \nconst quikdownVersion = '__QUIKDOWN_VERSION__';\n\n// Constants for reuse\nconst CLASS_PREFIX = 'quikdown-';\nconst PLACEHOLDER_CB = '§CB';\nconst PLACEHOLDER_IC = '§IC';\n\n// Escape map at module level\nconst ESC_MAP = {'&':'&amp;','<':'&lt;','>':'&gt;','\"':'&quot;',\"'\":'&#39;'};\n\n// Single source of truth for all style definitions - optimized\nconst QUIKDOWN_STYLES = {\n h1: 'font-size:2em;font-weight:600;margin:.67em 0;text-align:left',\n h2: 'font-size:1.5em;font-weight:600;margin:.83em 0',\n h3: 'font-size:1.25em;font-weight:600;margin:1em 0',\n h4: 'font-size:1em;font-weight:600;margin:1.33em 0',\n h5: 'font-size:.875em;font-weight:600;margin:1.67em 0',\n h6: 'font-size:.85em;font-weight:600;margin:2em 0',\n pre: 'background:#f4f4f4;padding:10px;border-radius:4px;overflow-x:auto;margin:1em 0',\n code: 'background:#f0f0f0;padding:2px 4px;border-radius:3px;font-family:monospace',\n blockquote: 'border-left:4px solid #ddd;margin-left:0;padding-left:1em',\n table: 'border-collapse:collapse;width:100%;margin:1em 0',\n th: 'border:1px solid #ddd;padding:8px;background-color:#f2f2f2;font-weight:bold;text-align:left',\n td: 'border:1px solid #ddd;padding:8px;text-align:left',\n hr: 'border:none;border-top:1px solid #ddd;margin:1em 0',\n img: 'max-width:100%;height:auto',\n a: 'color:#06c;text-decoration:underline',\n strong: 'font-weight:bold',\n em: 'font-style:italic',\n del: 'text-decoration:line-through',\n ul: 'margin:.5em 0;padding-left:2em',\n ol: 'margin:.5em 0;padding-left:2em',\n li: 'margin:.25em 0',\n // Task list specific styles\n 'task-item': 'list-style:none',\n 'task-checkbox': 'margin-right:.5em'\n};\n\n// Factory function to create getAttr for a given context\nfunction createGetAttr(inline_styles, styles) {\n return function(tag, additionalStyle = '') {\n if (inline_styles) {\n let style = styles[tag];\n if (!style && !additionalStyle) return '';\n \n // Remove default text-align if we're adding a different alignment\n if (additionalStyle && additionalStyle.includes('text-align') && style && style.includes('text-align')) {\n style = style.replace(/text-align:[^;]+;?/, '').trim();\n if (style && !style.endsWith(';')) style += ';';\n }\n \n /* istanbul ignore next - defensive: additionalStyle without style doesn't occur with current tags */\n const fullStyle = additionalStyle ? (style ? `${style}${additionalStyle}` : additionalStyle) : style;\n return ` style=\"${fullStyle}\"`;\n } else {\n const classAttr = ` class=\"${CLASS_PREFIX}${tag}\"`;\n // Apply inline styles for alignment even when using CSS classes\n if (additionalStyle) {\n return `${classAttr} style=\"${additionalStyle}\"`;\n }\n return classAttr;\n }\n };\n}\n\nfunction quikdown(markdown, options = {}) {\n if (!markdown || typeof markdown !== 'string') {\n return '';\n }\n \n const { fence_plugin, inline_styles = false, bidirectional = false, lazy_linefeeds = false } = options;\n const styles = QUIKDOWN_STYLES; // Use module-level styles\n const getAttr = createGetAttr(inline_styles, styles); // Create getAttr once\n\n // Escape HTML entities to prevent XSS\n function escapeHtml(text) {\n return text.replace(/[&<>\"']/g, m => ESC_MAP[m]);\n }\n \n // Helper to add data-qd attributes for bidirectional support\n const dataQd = bidirectional ? (marker) => ` data-qd=\"${escapeHtml(marker)}\"` : () => '';\n \n // Sanitize URLs to prevent XSS attacks\n function sanitizeUrl(url, allowUnsafe = false) {\n /* istanbul ignore next - defensive programming, regex ensures url is never empty */\n if (!url) return '';\n \n // If unsafe URLs are explicitly allowed, return as-is\n if (allowUnsafe) return url;\n \n const trimmedUrl = url.trim();\n const lowerUrl = trimmedUrl.toLowerCase();\n \n // Block dangerous protocols\n const dangerousProtocols = ['javascript:', 'vbscript:', 'data:'];\n \n for (const protocol of dangerousProtocols) {\n if (lowerUrl.startsWith(protocol)) {\n // Exception: Allow data:image/* for images\n if (protocol === 'data:' && lowerUrl.startsWith('data:image/')) {\n return trimmedUrl;\n }\n // Return safe empty link for dangerous protocols\n return '#';\n }\n }\n \n return trimmedUrl;\n }\n\n // Process the markdown in phases\n let html = markdown;\n \n // Phase 1: Extract and protect code blocks and inline code\n const codeBlocks = [];\n const inlineCodes = [];\n \n // Extract fenced code blocks first (supports both ``` and ~~~)\n // Match paired fences - ``` with ``` and ~~~ with ~~~\n // Fence must be at start of line\n html = html.replace(/^(```|~~~)([^\\n]*)\\n([\\s\\S]*?)^\\1$/gm, (match, fence, lang, code) => {\n const placeholder = `${PLACEHOLDER_CB}${codeBlocks.length}§`;\n \n // Trim the language specification\n const langTrimmed = lang ? lang.trim() : '';\n \n // If custom fence plugin is provided, use it (v1.1.0: object format required)\n if (fence_plugin && fence_plugin.render && typeof fence_plugin.render === 'function') {\n codeBlocks.push({\n lang: langTrimmed,\n code: code.trimEnd(),\n custom: true,\n fence: fence,\n hasReverse: !!fence_plugin.reverse\n });\n } else {\n codeBlocks.push({\n lang: langTrimmed,\n code: escapeHtml(code.trimEnd()),\n custom: false,\n fence: fence\n });\n }\n return placeholder;\n });\n \n // Extract inline code\n html = html.replace(/`([^`]+)`/g, (match, code) => {\n const placeholder = `${PLACEHOLDER_IC}${inlineCodes.length}§`;\n inlineCodes.push(escapeHtml(code));\n return placeholder;\n });\n \n // Now escape HTML in the rest of the content\n html = escapeHtml(html);\n \n // Phase 2: Process block elements\n \n // Process tables\n html = processTable(html, getAttr);\n \n // Process headings (supports optional trailing #'s)\n html = html.replace(/^(#{1,6})\\s+(.+?)\\s*#*$/gm, (match, hashes, content) => {\n const level = hashes.length;\n return `<h${level}${getAttr('h' + level)}${dataQd(hashes)}>${content}</h${level}>`;\n });\n \n // Process blockquotes (must handle escaped > since we already escaped HTML)\n html = html.replace(/^&gt;\\s+(.+)$/gm, `<blockquote${getAttr('blockquote')}>$1</blockquote>`);\n // Merge consecutive blockquotes\n html = html.replace(/<\\/blockquote>\\n<blockquote>/g, '\\n');\n \n // Process horizontal rules (allow trailing spaces)\n html = html.replace(/^---+\\s*$/gm, `<hr${getAttr('hr')}>`);\n \n // Process lists\n html = processLists(html, getAttr, inline_styles, bidirectional);\n \n // Phase 3: Process inline elements\n \n // Images (must come before links, with URL sanitization)\n html = html.replace(/!\\[([^\\]]*)\\]\\(([^)]+)\\)/g, (match, alt, src) => {\n const sanitizedSrc = sanitizeUrl(src, options.allow_unsafe_urls);\n const altAttr = bidirectional && alt ? ` data-qd-alt=\"${escapeHtml(alt)}\"` : '';\n const srcAttr = bidirectional ? ` data-qd-src=\"${escapeHtml(src)}\"` : '';\n return `<img${getAttr('img')} src=\"${sanitizedSrc}\" alt=\"${alt}\"${altAttr}${srcAttr}${dataQd('!')}>`;\n });\n \n // Links (with URL sanitization)\n html = html.replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, (match, text, href) => {\n // Sanitize URL to prevent XSS\n const sanitizedHref = sanitizeUrl(href, options.allow_unsafe_urls);\n const isExternal = /^https?:\\/\\//i.test(sanitizedHref);\n const rel = isExternal ? ' rel=\"noopener noreferrer\"' : '';\n const textAttr = bidirectional ? ` data-qd-text=\"${escapeHtml(text)}\"` : '';\n return `<a${getAttr('a')} href=\"${sanitizedHref}\"${rel}${textAttr}${dataQd('[')}>${text}</a>`;\n });\n \n // Autolinks - convert bare URLs to clickable links\n html = html.replace(/(^|\\s)(https?:\\/\\/[^\\s<]+)/g, (match, prefix, url) => {\n const sanitizedUrl = sanitizeUrl(url, options.allow_unsafe_urls);\n return `${prefix}<a${getAttr('a')} href=\"${sanitizedUrl}\" rel=\"noopener noreferrer\">${url}</a>`;\n });\n \n // Process inline formatting (bold, italic, strikethrough)\n const inlinePatterns = [\n [/\\*\\*(.+?)\\*\\*/g, 'strong', '**'],\n [/__(.+?)__/g, 'strong', '__'],\n [/(?<!\\*)\\*(?!\\*)(.+?)(?<!\\*)\\*(?!\\*)/g, 'em', '*'],\n [/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g, 'em', '_'],\n [/~~(.+?)~~/g, 'del', '~~']\n ];\n \n inlinePatterns.forEach(([pattern, tag, marker]) => {\n html = html.replace(pattern, `<${tag}${getAttr(tag)}${dataQd(marker)}>$1</${tag}>`);\n });\n \n // Line breaks\n if (lazy_linefeeds) {\n // Lazy linefeeds: single newline becomes <br> (except between paragraphs and after/before block elements)\n const blocks = [];\n let bi = 0;\n \n // Protect tables and lists \n html = html.replace(/<(table|[uo]l)[^>]*>[\\s\\S]*?<\\/\\1>/g, m => {\n blocks[bi] = m;\n return `§B${bi++}§`;\n });\n \n // Handle paragraphs and block elements\n html = html.replace(/\\n\\n+/g, '§P§')\n // After block elements\n .replace(/(<\\/(?:h[1-6]|blockquote|pre)>)\\n/g, '$1§N§')\n .replace(/(<(?:h[1-6]|blockquote|pre|hr)[^>]*>)\\n/g, '$1§N§')\n // Before block elements \n .replace(/\\n(<(?:h[1-6]|blockquote|pre|hr)[^>]*>)/g, '§N§$1')\n .replace(/\\n(§B\\d+§)/g, '§N§$1')\n .replace(/(§B\\d+§)\\n/g, '$1§N§')\n // Convert remaining newlines\n .replace(/\\n/g, `<br${getAttr('br')}>`)\n // Restore\n .replace(/§N§/g, '\\n')\n .replace(/§P§/g, '</p><p>');\n \n // Restore protected blocks\n blocks.forEach((b, i) => html = html.replace(`§B${i}§`, b));\n \n html = '<p>' + html + '</p>';\n } else {\n // Standard: two spaces at end of line for line breaks\n html = html.replace(/ $/gm, `<br${getAttr('br')}>`);\n \n // Paragraphs (double newlines)\n // Don't add </p> after block elements (they're not in paragraphs)\n html = html.replace(/\\n\\n+/g, (match, offset) => {\n // Check if we're after a block element closing tag\n const before = html.substring(0, offset);\n if (before.match(/<\\/(h[1-6]|blockquote|ul|ol|table|pre|hr)>$/)) {\n return '<p>'; // Just open a new paragraph\n }\n return '</p><p>'; // Normal paragraph break\n });\n html = '<p>' + html + '</p>';\n }\n \n // Clean up empty paragraphs and unwrap block elements\n const cleanupPatterns = [\n [/<p><\\/p>/g, ''],\n [/<p>(<h[1-6][^>]*>)/g, '$1'],\n [/(<\\/h[1-6]>)<\\/p>/g, '$1'],\n [/<p>(<blockquote[^>]*>)/g, '$1'],\n [/(<\\/blockquote>)<\\/p>/g, '$1'],\n [/<p>(<ul[^>]*>|<ol[^>]*>)/g, '$1'],\n [/(<\\/ul>|<\\/ol>)<\\/p>/g, '$1'],\n [/<p>(<hr[^>]*>)<\\/p>/g, '$1'],\n [/<p>(<table[^>]*>)/g, '$1'],\n [/(<\\/table>)<\\/p>/g, '$1'],\n [/<p>(<pre[^>]*>)/g, '$1'],\n [/(<\\/pre>)<\\/p>/g, '$1'],\n [new RegExp(`<p>(${PLACEHOLDER_CB}\\\\d+§)<\\/p>`, 'g'), '$1']\n ];\n \n cleanupPatterns.forEach(([pattern, replacement]) => {\n html = html.replace(pattern, replacement);\n });\n \n // Fix orphaned closing </p> tags after block elements\n // When a paragraph follows a block element, ensure it has opening <p>\n html = html.replace(/(<\\/(?:h[1-6]|blockquote|ul|ol|table|pre|hr)>)\\n([^<])/g, '$1\\n<p>$2');\n \n // Phase 4: Restore code blocks and inline code\n \n // Restore code blocks\n codeBlocks.forEach((block, i) => {\n let replacement;\n \n if (block.custom && fence_plugin && fence_plugin.render) {\n // Use custom fence plugin (v1.1.0: object format with render function)\n replacement = fence_plugin.render(block.code, block.lang);\n \n // If plugin returns undefined, fall back to default rendering\n if (replacement === undefined) {\n const langClass = !inline_styles && block.lang ? ` class=\"language-${block.lang}\"` : '';\n const codeAttr = inline_styles ? getAttr('code') : langClass;\n const langAttr = bidirectional && block.lang ? ` data-qd-lang=\"${escapeHtml(block.lang)}\"` : '';\n const fenceAttr = bidirectional ? ` data-qd-fence=\"${escapeHtml(block.fence)}\"` : '';\n replacement = `<pre${getAttr('pre')}${fenceAttr}${langAttr}><code${codeAttr}>${escapeHtml(block.code)}</code></pre>`;\n } else if (bidirectional) {\n // If bidirectional and plugin provided HTML, add data attributes for roundtrip\n replacement = replacement.replace(/^<(\\w+)/, \n `<$1 data-qd-fence=\"${escapeHtml(block.fence)}\" data-qd-lang=\"${escapeHtml(block.lang)}\" data-qd-source=\"${escapeHtml(block.code)}\"`);\n }\n } else {\n // Default rendering\n const langClass = !inline_styles && block.lang ? ` class=\"language-${block.lang}\"` : '';\n const codeAttr = inline_styles ? getAttr('code') : langClass;\n const langAttr = bidirectional && block.lang ? ` data-qd-lang=\"${escapeHtml(block.lang)}\"` : '';\n const fenceAttr = bidirectional ? ` data-qd-fence=\"${escapeHtml(block.fence)}\"` : '';\n replacement = `<pre${getAttr('pre')}${fenceAttr}${langAttr}><code${codeAttr}>${block.code}</code></pre>`;\n }\n \n const placeholder = `${PLACEHOLDER_CB}${i}§`;\n html = html.replace(placeholder, replacement);\n });\n \n // Restore inline code\n inlineCodes.forEach((code, i) => {\n const placeholder = `${PLACEHOLDER_IC}${i}§`;\n html = html.replace(placeholder, `<code${getAttr('code')}${dataQd('`')}>${code}</code>`);\n });\n \n return html.trim();\n}\n\n/**\n * Process inline markdown formatting\n */\nfunction processInlineMarkdown(text, getAttr) {\n \n // Process inline formatting patterns\n const patterns = [\n [/\\*\\*(.+?)\\*\\*/g, 'strong'],\n [/__(.+?)__/g, 'strong'],\n [/(?<!\\*)\\*(?!\\*)(.+?)(?<!\\*)\\*(?!\\*)/g, 'em'],\n [/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g, 'em'],\n [/~~(.+?)~~/g, 'del'],\n [/`([^`]+)`/g, 'code']\n ];\n \n patterns.forEach(([pattern, tag]) => {\n text = text.replace(pattern, `<${tag}${getAttr(tag)}>$1</${tag}>`);\n });\n \n return text;\n}\n\n/**\n * Process markdown tables\n */\nfunction processTable(text, getAttr) {\n const lines = text.split('\\n');\n const result = [];\n let inTable = false;\n let tableLines = [];\n \n for (let i = 0; i < lines.length; i++) {\n const line = lines[i].trim();\n \n // Check if this line looks like a table row (with or without trailing |)\n if (line.includes('|') && (line.startsWith('|') || /[^\\\\|]/.test(line))) {\n if (!inTable) {\n inTable = true;\n tableLines = [];\n }\n tableLines.push(line);\n } else {\n // Not a table line\n if (inTable) {\n // Process the accumulated table\n const tableHtml = buildTable(tableLines, getAttr);\n if (tableHtml) {\n result.push(tableHtml);\n } else {\n // Not a valid table, restore original lines\n result.push(...tableLines);\n }\n inTable = false;\n tableLines = [];\n }\n result.push(lines[i]);\n }\n }\n \n // Handle table at end of text\n if (inTable && tableLines.length > 0) {\n const tableHtml = buildTable(tableLines, getAttr);\n if (tableHtml) {\n result.push(tableHtml);\n } else {\n result.push(...tableLines);\n }\n }\n \n return result.join('\\n');\n}\n\n/**\n * Build an HTML table from markdown table lines\n */\nfunction buildTable(lines, getAttr) {\n \n if (lines.length < 2) return null;\n \n // Check for separator line (second line should be the separator)\n let separatorIndex = -1;\n for (let i = 1; i < lines.length; i++) {\n // Support separator with or without leading/trailing pipes\n if (/^\\|?[\\s\\-:|]+\\|?$/.test(lines[i]) && lines[i].includes('-')) {\n separatorIndex = i;\n break;\n }\n }\n \n if (separatorIndex === -1) return null;\n \n const headerLines = lines.slice(0, separatorIndex);\n const bodyLines = lines.slice(separatorIndex + 1);\n \n // Parse alignment from separator\n const separator = lines[separatorIndex];\n // Handle pipes at start/end or not\n const separatorCells = separator.trim().replace(/^\\|/, '').replace(/\\|$/, '').split('|');\n const alignments = separatorCells.map(cell => {\n const trimmed = cell.trim();\n if (trimmed.startsWith(':') && trimmed.endsWith(':')) return 'center';\n if (trimmed.endsWith(':')) return 'right';\n return 'left';\n });\n \n let html = `<table${getAttr('table')}>\\n`;\n \n // Build header\n // Note: headerLines will always have length > 0 since separatorIndex starts from 1\n html += `<thead${getAttr('thead')}>\\n`;\n headerLines.forEach(line => {\n html += `<tr${getAttr('tr')}>\\n`;\n // Handle pipes at start/end or not\n const cells = line.trim().replace(/^\\|/, '').replace(/\\|$/, '').split('|');\n cells.forEach((cell, i) => {\n const alignStyle = alignments[i] && alignments[i] !== 'left' ? `text-align:${alignments[i]}` : '';\n const processedCell = processInlineMarkdown(cell.trim(), getAttr);\n html += `<th${getAttr('th', alignStyle)}>${processedCell}</th>\\n`;\n });\n html += '</tr>\\n';\n });\n html += '</thead>\\n';\n \n // Build body\n if (bodyLines.length > 0) {\n html += `<tbody${getAttr('tbody')}>\\n`;\n bodyLines.forEach(line => {\n html += `<tr${getAttr('tr')}>\\n`;\n // Handle pipes at start/end or not\n const cells = line.trim().replace(/^\\|/, '').replace(/\\|$/, '').split('|');\n cells.forEach((cell, i) => {\n const alignStyle = alignments[i] && alignments[i] !== 'left' ? `text-align:${alignments[i]}` : '';\n const processedCell = processInlineMarkdown(cell.trim(), getAttr);\n html += `<td${getAttr('td', alignStyle)}>${processedCell}</td>\\n`;\n });\n html += '</tr>\\n';\n });\n html += '</tbody>\\n';\n }\n \n html += '</table>';\n return html;\n}\n\n/**\n * Process markdown lists (ordered and unordered)\n */\nfunction processLists(text, getAttr, inline_styles, bidirectional) {\n \n const lines = text.split('\\n');\n const result = [];\n let listStack = []; // Track nested lists\n \n // Helper to escape HTML for data-qd attributes\n const escapeHtml = (text) => text.replace(/[&<>\"']/g, m => ({'&':'&amp;','<':'&lt;','>':'&gt;','\"':'&quot;',\"'\":'&#39;'})[m]);\n const dataQd = bidirectional ? (marker) => ` data-qd=\"${escapeHtml(marker)}\"` : () => '';\n \n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n const match = line.match(/^(\\s*)([*\\-+]|\\d+\\.)\\s+(.+)$/);\n \n if (match) {\n const [, indent, marker, content] = match;\n const level = Math.floor(indent.length / 2);\n const isOrdered = /^\\d+\\./.test(marker);\n const listType = isOrdered ? 'ol' : 'ul';\n \n // Check for task list items\n let listItemContent = content;\n let taskListClass = '';\n const taskMatch = content.match(/^\\[([x ])\\]\\s+(.*)$/i);\n if (taskMatch && !isOrdered) {\n const [, checked, taskContent] = taskMatch;\n const isChecked = checked.toLowerCase() === 'x';\n const checkboxAttr = inline_styles \n ? ' style=\"margin-right:.5em\"' \n : ` class=\"${CLASS_PREFIX}task-checkbox\"`;\n listItemContent = `<input type=\"checkbox\"${checkboxAttr}${isChecked ? ' checked' : ''} disabled> ${taskContent}`;\n taskListClass = inline_styles ? ' style=\"list-style:none\"' : ` class=\"${CLASS_PREFIX}task-item\"`;\n }\n \n // Close deeper levels\n while (listStack.length > level + 1) {\n const list = listStack.pop();\n result.push(`</${list.type}>`);\n }\n \n // Open new level if needed\n if (listStack.length === level) {\n // Need to open a new list\n listStack.push({ type: listType, level });\n result.push(`<${listType}${getAttr(listType)}>`);\n } else if (listStack.length === level + 1) {\n // Check if we need to switch list type\n const currentList = listStack[listStack.length - 1];\n if (currentList.type !== listType) {\n result.push(`</${currentList.type}>`);\n listStack.pop();\n listStack.push({ type: listType, level });\n result.push(`<${listType}${getAttr(listType)}>`);\n }\n }\n \n const liAttr = taskListClass || getAttr('li');\n result.push(`<li${liAttr}${dataQd(marker)}>${listItemContent}</li>`);\n } else {\n // Not a list item, close all lists\n while (listStack.length > 0) {\n const list = listStack.pop();\n result.push(`</${list.type}>`);\n }\n result.push(line);\n }\n }\n \n // Close any remaining lists\n while (listStack.length > 0) {\n const list = listStack.pop();\n result.push(`</${list.type}>`);\n }\n \n return result.join('\\n');\n}\n\n/**\n * Emit CSS styles for quikdown elements\n * @param {string} prefix - Optional class prefix (default: 'quikdown-')\n * @param {string} theme - Optional theme: 'light' (default) or 'dark'\n * @returns {string} CSS string with quikdown styles\n */\nquikdown.emitStyles = function(prefix = 'quikdown-', theme = 'light') {\n const styles = QUIKDOWN_STYLES;\n \n // Define theme color overrides\n const themeOverrides = {\n dark: {\n '#f4f4f4': '#2a2a2a', // pre background\n '#f0f0f0': '#2a2a2a', // code background\n '#f2f2f2': '#2a2a2a', // th background\n '#ddd': '#3a3a3a', // borders\n '#06c': '#6db3f2', // links\n _textColor: '#e0e0e0'\n },\n light: {\n _textColor: '#333' // Explicit text color for light theme\n }\n };\n \n let css = '';\n for (const [tag, style] of Object.entries(styles)) {\n let themedStyle = style;\n \n // Apply theme overrides if dark theme\n if (theme === 'dark' && themeOverrides.dark) {\n // Replace colors\n for (const [oldColor, newColor] of Object.entries(themeOverrides.dark)) {\n if (!oldColor.startsWith('_')) {\n themedStyle = themedStyle.replace(new RegExp(oldColor, 'g'), newColor);\n }\n }\n \n // Add text color for certain elements in dark theme\n const needsTextColor = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'td', 'li', 'blockquote'];\n if (needsTextColor.includes(tag)) {\n themedStyle += `;color:${themeOverrides.dark._textColor}`;\n }\n } else if (theme === 'light' && themeOverrides.light) {\n // Add explicit text color for light theme elements too\n const needsTextColor = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'td', 'li', 'blockquote'];\n if (needsTextColor.includes(tag)) {\n themedStyle += `;color:${themeOverrides.light._textColor}`;\n }\n }\n \n css += `.${prefix}${tag} { ${themedStyle} }\\n`;\n }\n \n return css;\n};\n\n/**\n * Configure quikdown with options and return a function\n * @param {Object} options - Configuration options\n * @returns {Function} Configured quikdown function\n */\nquikdown.configure = function(options) {\n return function(markdown) {\n return quikdown(markdown, options);\n };\n};\n\n/**\n * Version information\n */\nquikdown.version = quikdownVersion;\n\n// Export for both CommonJS and ES6\n/* istanbul ignore next */\nif (typeof module !== 'undefined' && module.exports) {\n module.exports = quikdown;\n}\n\n// For browser global\n/* istanbul ignore next */\nif (typeof window !== 'undefined') {\n window.quikdown = quikdown;\n}\n\nexport default quikdown;","/**\n * quikdown_bd - Bidirectional markdown/HTML converter\n * Extends core quikdown with HTML→Markdown conversion\n * \n * Uses data-qd attributes to preserve original markdown syntax\n * Enables HTML→Markdown conversion for quikdown-generated HTML\n */\n\nimport quikdown from './quikdown.js';\n\n/**\n * Create bidirectional version by extending quikdown\n * This wraps quikdown and adds the toMarkdown method\n */\nfunction quikdown_bd(markdown, options = {}) {\n // Use core quikdown with bidirectional flag to add data-qd attributes\n return quikdown(markdown, { ...options, bidirectional: true });\n}\n\n// Copy all properties and methods from quikdown (including version)\nObject.keys(quikdown).forEach(key => {\n quikdown_bd[key] = quikdown[key];\n});\n\n// Add the toMarkdown method for HTML→Markdown conversion\nquikdown_bd.toMarkdown = function(htmlOrElement, options = {}) {\n // Accept either HTML string or DOM element\n let container;\n if (typeof htmlOrElement === 'string') {\n container = document.createElement('div');\n container.innerHTML = htmlOrElement;\n } else if (htmlOrElement instanceof Element) {\n /* istanbul ignore next - browser-only code path, not testable in jsdom */\n container = htmlOrElement;\n } else {\n return '';\n }\n \n // Walk the DOM tree and reconstruct markdown\n function walkNode(node, parentContext = {}) {\n if (node.nodeType === Node.TEXT_NODE) {\n // Return text content, preserving whitespace where needed\n return node.textContent;\n }\n \n if (node.nodeType !== Node.ELEMENT_NODE) {\n return '';\n }\n \n const tag = node.tagName.toLowerCase();\n const dataQd = node.getAttribute('data-qd');\n \n // Process children with context\n let childContent = '';\n for (let child of node.childNodes) {\n childContent += walkNode(child, { parentTag: tag, ...parentContext });\n }\n \n // Determine markdown based on element and attributes\n switch (tag) {\n case 'h1':\n case 'h2':\n case 'h3':\n case 'h4':\n case 'h5':\n case 'h6':\n const level = parseInt(tag[1]);\n const prefix = dataQd || '#'.repeat(level);\n return `${prefix} ${childContent.trim()}\\n\\n`;\n \n case 'strong':\n case 'b':\n if (!childContent) return ''; // Don't add markers for empty content\n const boldMarker = dataQd || '**';\n return `${boldMarker}${childContent}${boldMarker}`;\n \n case 'em':\n case 'i':\n if (!childContent) return ''; // Don't add markers for empty content\n const emMarker = dataQd || '*';\n return `${emMarker}${childContent}${emMarker}`;\n \n case 'del':\n case 's':\n case 'strike':\n if (!childContent) return ''; // Don't add markers for empty content\n const delMarker = dataQd || '~~';\n return `${delMarker}${childContent}${delMarker}`;\n \n case 'code':\n // Note: code inside pre is handled directly by the pre case using querySelector\n if (!childContent) return ''; // Don't add markers for empty content\n const codeMarker = dataQd || '`';\n return `${codeMarker}${childContent}${codeMarker}`;\n \n case 'pre':\n const fence = node.getAttribute('data-qd-fence') || dataQd || '```';\n const lang = node.getAttribute('data-qd-lang') || '';\n \n // Check if this was created by a fence plugin with reverse handler\n if (options.fence_plugin && options.fence_plugin.reverse && lang) {\n try {\n const result = options.fence_plugin.reverse(node);\n if (result && result.content) {\n const fenceMarker = result.fence || fence;\n const langStr = result.lang || lang;\n return `${fenceMarker}${langStr}\\n${result.content}\\n${fenceMarker}\\n\\n`;\n }\n } catch (err) {\n console.warn('Fence reverse handler error:', err);\n // Fall through to default handling\n }\n }\n \n // Fallback: use data-qd-source if available\n const source = node.getAttribute('data-qd-source');\n if (source) {\n return `${fence}${lang}\\n${source}\\n${fence}\\n\\n`;\n }\n \n // Final fallback: extract text content\n const codeEl = node.querySelector('code');\n const codeContent = codeEl ? codeEl.textContent : childContent;\n return `${fence}${lang}\\n${codeContent.trimEnd()}\\n${fence}\\n\\n`;\n \n case 'blockquote':\n const quoteMarker = dataQd || '>';\n const lines = childContent.trim().split('\\n');\n return lines.map(line => `${quoteMarker} ${line}`).join('\\n') + '\\n\\n';\n \n case 'hr':\n const hrMarker = dataQd || '---';\n return `${hrMarker}\\n\\n`;\n \n case 'br':\n const brMarker = dataQd || ' ';\n return `${brMarker}\\n`;\n \n case 'a':\n const linkText = node.getAttribute('data-qd-text') || childContent.trim();\n const href = node.getAttribute('href') || '';\n // Check for autolinks\n if (linkText === href && !dataQd) {\n return `<${href}>`;\n }\n return `[${linkText}](${href})`;\n \n case 'img':\n const alt = node.getAttribute('data-qd-alt') || node.getAttribute('alt') || '';\n const src = node.getAttribute('data-qd-src') || node.getAttribute('src') || '';\n const imgMarker = dataQd || '!';\n return `${imgMarker}[${alt}](${src})`;\n \n case 'ul':\n case 'ol':\n return walkList(node, tag === 'ol') + '\\n';\n \n case 'li':\n // Handled by list processor\n return childContent;\n \n case 'table':\n return walkTable(node) + '\\n\\n';\n \n case 'p':\n // Check if it's actually a paragraph or just a wrapper\n if (childContent.trim()) {\n // Check if paragraph ends with a line that's just whitespace\n // This indicates an intentional blank line before the next element\n const lines = childContent.split('\\n');\n let content = childContent.trim();\n \n // If the last line(s) are just whitespace, preserve one blank line\n if (lines.length > 1) {\n let trailingBlankLines = 0;\n for (let i = lines.length - 1; i >= 0; i--) {\n if (lines[i].trim() === '') {\n trailingBlankLines++;\n } else {\n break;\n }\n }\n if (trailingBlankLines > 0) {\n // Add a line with just a space, followed by single newline\n // The \\n\\n will be added below for paragraph separation\n content = content + '\\n ';\n // Only add one newline since we're preserving the space line\n return content + '\\n';\n }\n }\n \n return content + '\\n\\n';\n }\n return '';\n \n case 'div':\n // Check if this was created by a fence plugin with reverse handler\n const divLang = node.getAttribute('data-qd-lang');\n const divFence = node.getAttribute('data-qd-fence');\n \n if (divLang && options.fence_plugin && options.fence_plugin.reverse) {\n try {\n const result = options.fence_plugin.reverse(node);\n if (result && result.content) {\n const fenceMarker = result.fence || divFence || '```';\n const langStr = result.lang || divLang;\n return `${fenceMarker}${langStr}\\n${result.content}\\n${fenceMarker}\\n\\n`;\n }\n } catch (err) {\n console.warn('Fence reverse handler error:', err);\n // Fall through to default handling\n }\n }\n \n // Fallback: use data-qd-source if available\n const divSource = node.getAttribute('data-qd-source');\n if (divSource && divFence) {\n return `${divFence}${divLang || ''}\\n${divSource}\\n${divFence}\\n\\n`;\n }\n \n // Check if it's a mermaid container\n if (node.classList && node.classList.contains('mermaid-container')) {\n const fence = node.getAttribute('data-qd-fence') || '```';\n const lang = node.getAttribute('data-qd-lang') || 'mermaid';\n \n // First check for data-qd-source attribute on the container\n const source = node.getAttribute('data-qd-source');\n if (source) {\n // Decode HTML entities from the attribute (mainly &quot;)\n const temp = document.createElement('textarea');\n temp.innerHTML = source;\n const code = temp.value;\n return `${fence}${lang}\\n${code}\\n${fence}\\n\\n`;\n }\n \n // Check for source on the pre.mermaid element\n const mermaidPre = node.querySelector('pre.mermaid');\n if (mermaidPre) {\n const preSource = mermaidPre.getAttribute('data-qd-source');\n if (preSource) {\n const temp = document.createElement('textarea');\n temp.innerHTML = preSource;\n const code = temp.value;\n return `${fence}${lang}\\n${code}\\n${fence}\\n\\n`;\n }\n }\n \n // Fallback: Look for the legacy .mermaid-source element\n const sourceElement = node.querySelector('.mermaid-source');\n if (sourceElement) {\n // Decode HTML entities\n const temp = document.createElement('div');\n temp.innerHTML = sourceElement.innerHTML;\n const code = temp.textContent;\n return `${fence}${lang}\\n${code}\\n${fence}\\n\\n`;\n }\n \n // Final fallback: try to extract from the mermaid element (unreliable after rendering)\n const mermaidElement = node.querySelector('.mermaid');\n if (mermaidElement && mermaidElement.textContent.includes('graph')) {\n return `${fence}${lang}\\n${mermaidElement.textContent.trim()}\\n${fence}\\n\\n`;\n }\n }\n // Check if it's a standalone mermaid diagram (legacy)\n if (node.classList && node.classList.contains('mermaid')) {\n const fence = node.getAttribute('data-qd-fence') || '```';\n const lang = node.getAttribute('data-qd-lang') || 'mermaid';\n const code = node.textContent.trim();\n return `${fence}${lang}\\n${code}\\n${fence}\\n\\n`;\n }\n // Pass through other divs\n return childContent;\n \n case 'span':\n // Pass through container elements\n return childContent;\n \n default:\n return childContent;\n }\n }\n \n // Walk list elements\n function walkList(listNode, isOrdered, depth = 0) {\n let result = '';\n let index = 1;\n const indent = ' '.repeat(depth);\n \n for (let child of listNode.children) {\n if (child.tagName !== 'LI') continue;\n \n const dataQd = child.getAttribute('data-qd');\n let marker = dataQd || (isOrdered ? `${index}.` : '-');\n \n // Check for task list checkbox\n const checkbox = child.querySelector('input[type=\"checkbox\"]');\n if (checkbox) {\n const checked = checkbox.checked ? 'x' : ' ';\n marker = '-';\n // Get text without the checkbox\n let text = '';\n for (let node of child.childNodes) {\n if (node.nodeType === Node.TEXT_NODE) {\n text += node.textContent;\n } else if (node.tagName && node.tagName !== 'INPUT') {\n text += walkNode(node);\n }\n }\n result += `${indent}${marker} [${checked}] ${text.trim()}\\n`;\n } else {\n let itemContent = '';\n \n for (let node of child.childNodes) {\n if (node.tagName === 'UL' || node.tagName === 'OL') {\n itemContent += walkList(node, node.tagName === 'OL', depth + 1);\n } else {\n itemContent += walkNode(node);\n }\n }\n \n result += `${indent}${marker} ${itemContent.trim()}\\n`;\n }\n \n index++;\n }\n \n return result;\n }\n \n // Walk table elements\n function walkTable(table) {\n let result = '';\n const alignData = table.getAttribute('data-qd-align');\n const alignments = alignData ? alignData.split(',') : [];\n \n // Process header\n const thead = table.querySelector('thead');\n if (thead) {\n const headerRow = thead.querySelector('tr');\n if (headerRow) {\n const headers = [];\n for (let th of headerRow.querySelectorAll('th')) {\n headers.push(th.textContent.trim());\n }\n result += '| ' + headers.join(' | ') + ' |\\n';\n \n // Add separator with alignment\n const separators = headers.map((_, i) => {\n const align = alignments[i] || 'left';\n if (align === 'center') return ':---:';\n if (align === 'right') return '---:';\n return '---';\n });\n result += '| ' + separators.join(' | ') + ' |\\n';\n }\n }\n \n // Process body\n const tbody = table.querySelector('tbody');\n if (tbody) {\n for (let row of tbody.querySelectorAll('tr')) {\n const cells = [];\n for (let td of row.querySelectorAll('td')) {\n cells.push(td.textContent.trim());\n }\n if (cells.length > 0) {\n result += '| ' + cells.join(' | ') + ' |\\n';\n }\n }\n }\n \n return result.trim();\n }\n \n // Process the DOM tree\n let markdown = walkNode(container);\n \n // Clean up\n markdown = markdown.replace(/\\n{3,}/g, '\\n\\n'); // Remove excessive newlines\n markdown = markdown.trim();\n \n return markdown;\n};\n\n// Override the configure method to return a bidirectional version\nquikdown_bd.configure = function(options) {\n return function(markdown) {\n return quikdown_bd(markdown, options);\n };\n};\n\n// Set version\n// Version is already copied from quikdown via Object.keys loop\n\n// Export for both module and browser\n/* istanbul ignore next */\nif (typeof module !== 'undefined' && module.exports) {\n module.exports = quikdown_bd;\n}\n\n/* istanbul ignore next */\nif (typeof window !== 'undefined') {\n window.quikdown_bd = quikdown_bd;\n}\n\nexport default quikdown_bd;"],"names":["CLASS_PREFIX","PLACEHOLDER_CB","ESC_MAP","QUIKDOWN_STYLES","h1","h2","h3","h4","h5","h6","pre","code","blockquote","table","th","td","hr","img","a","strong","em","del","ul","ol","li","quikdown","markdown","options","fence_plugin","inline_styles","bidirectional","lazy_linefeeds","getAttr","styles","tag","additionalStyle","style","includes","replace","trim","endsWith","classAttr","createGetAttr","escapeHtml","text","m","dataQd","marker","sanitizeUrl","url","allowUnsafe","trimmedUrl","lowerUrl","toLowerCase","dangerousProtocols","protocol","startsWith","html","codeBlocks","inlineCodes","match","fence","lang","placeholder","length","langTrimmed","render","push","trimEnd","custom","hasReverse","reverse","lines","split","result","inTable","tableLines","i","line","test","tableHtml","buildTable","join","processTable","hashes","content","level","listStack","indent","Math","floor","isOrdered","listType","listItemContent","taskListClass","taskMatch","checked","taskContent","isChecked","list","pop","type","currentList","liAttr","processLists","alt","src","sanitizedSrc","allow_unsafe_urls","altAttr","srcAttr","href","sanitizedHref","rel","textAttr","prefix","sanitizedUrl","forEach","pattern","blocks","bi","b","offset","substring","RegExp","replacement","block","undefined","langClass","codeAttr","langAttr","fenceAttr","processInlineMarkdown","separatorIndex","headerLines","slice","bodyLines","alignments","map","cell","trimmed","alignStyle","processedCell","quikdown_bd","emitStyles","theme","themeOverrides","_textColor","css","Object","entries","themedStyle","oldColor","newColor","configure","version","module","exports","window","keys","key","toMarkdown","htmlOrElement","container","document","createElement","innerHTML","Element","walkNode","node","parentContext","nodeType","Node","TEXT_NODE","textContent","ELEMENT_NODE","tagName","getAttribute","childContent","child","childNodes","parentTag","parseInt","repeat","boldMarker","emMarker","delMarker","codeMarker","fenceMarker","err","console","warn","source","codeEl","querySelector","quoteMarker","linkText","walkList","alignData","thead","headerRow","headers","querySelectorAll","_","align","tbody","row","cells","walkTable","trailingBlankLines","divLang","divFence","divSource","classList","contains","temp","value","mermaidPre","preSource","sourceElement","mermaidElement","listNode","depth","index","children","checkbox","itemContent"],"mappings":";;;;;;AAcA,MAGMA,EAAe,YACfC,EAAiB,MAIjBC,EAAU,CAAC,IAAI,QAAQ,IAAI,OAAO,IAAI,OAAO,IAAI,SAAS,IAAI,SAG9DC,EAAkB,CACpBC,GAAI,+DACJC,GAAI,iDACJC,GAAI,gDACJC,GAAI,gDACJC,GAAI,mDACJC,GAAI,+CACJC,IAAK,iFACLC,KAAM,6EACNC,WAAY,4DACZC,MAAO,mDACPC,GAAI,8FACJC,GAAI,oDACJC,GAAI,qDACJC,IAAK,6BACLC,EAAG,uCACHC,OAAQ,mBACRC,GAAI,oBACJC,IAAK,+BACLC,GAAI,iCACJC,GAAI,iCACJC,GAAI,iBAEJ,YAAa,kBACb,gBAAiB,qBA8BrB,SAASC,EAASC,EAAUC,EAAU,IAClC,IAAKD,GAAgC,iBAAbA,EACpB,MAAO,GAGX,MAAME,aAAEA,EAAYC,cAAEA,GAAgB,EAAKC,cAAEA,GAAgB,EAAKC,eAAEA,GAAiB,GAAUJ,EAEzFK,EAjCV,SAAuBH,EAAeI,GAClC,OAAO,SAASC,EAAKC,EAAkB,IACnC,GAAIN,EAAe,CACf,IAAIO,EAAQH,EAAOC,GACnB,OAAKE,GAAUD,GAGXA,GAAmBA,EAAgBE,SAAS,eAAiBD,GAASA,EAAMC,SAAS,gBACrFD,EAAQA,EAAME,QAAQ,qBAAsB,IAAIC,OAC5CH,IAAUA,EAAMI,SAAS,OAAMJ,GAAS,MAKzC,WADWD,EAAmBC,EAAQ,GAAGA,IAAQD,IAAoBA,EAAmBC,MATxD,EAW3C,CAAO,CACH,MAAMK,EAAY,WAAWzC,IAAekC,KAE5C,OAAIC,EACO,GAAGM,Y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