quikdown 1.2.3 → 1.2.7
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.
- package/README.md +20 -25
- package/dist/quikdown.cjs +8 -5
- package/dist/quikdown.dark.css +1 -1
- package/dist/quikdown.esm.js +8 -5
- package/dist/quikdown.esm.min.js +2 -2
- package/dist/quikdown.esm.min.js.gz +0 -0
- package/dist/quikdown.esm.min.js.map +1 -1
- package/dist/quikdown.light.css +1 -1
- package/dist/quikdown.umd.js +8 -5
- package/dist/quikdown.umd.min.js +2 -2
- package/dist/quikdown.umd.min.js.gz +0 -0
- package/dist/quikdown.umd.min.js.map +1 -1
- package/dist/quikdown_ast.cjs +2 -2
- package/dist/quikdown_ast.esm.js +2 -2
- package/dist/quikdown_ast.esm.min.js +2 -2
- package/dist/quikdown_ast.esm.min.js.gz +0 -0
- package/dist/quikdown_ast.umd.js +2 -2
- package/dist/quikdown_ast.umd.min.js +2 -2
- package/dist/quikdown_ast.umd.min.js.gz +0 -0
- package/dist/quikdown_ast_html.cjs +3 -3
- package/dist/quikdown_ast_html.esm.js +3 -3
- package/dist/quikdown_ast_html.esm.min.js +2 -2
- package/dist/quikdown_ast_html.esm.min.js.gz +0 -0
- package/dist/quikdown_ast_html.umd.js +3 -3
- package/dist/quikdown_ast_html.umd.min.js +2 -2
- package/dist/quikdown_ast_html.umd.min.js.gz +0 -0
- package/dist/quikdown_bd.cjs +8 -5
- package/dist/quikdown_bd.esm.js +8 -5
- package/dist/quikdown_bd.esm.min.js +2 -2
- package/dist/quikdown_bd.esm.min.js.gz +0 -0
- package/dist/quikdown_bd.esm.min.js.map +1 -1
- package/dist/quikdown_bd.umd.js +8 -5
- package/dist/quikdown_bd.umd.min.js +2 -2
- package/dist/quikdown_bd.umd.min.js.gz +0 -0
- package/dist/quikdown_bd.umd.min.js.map +1 -1
- package/dist/quikdown_edit.cjs +9 -5
- package/dist/quikdown_edit.esm.js +9 -5
- package/dist/quikdown_edit.esm.min.js +3 -3
- package/dist/quikdown_edit.esm.min.js.gz +0 -0
- package/dist/quikdown_edit.esm.min.js.map +1 -1
- package/dist/quikdown_edit.umd.js +9 -5
- package/dist/quikdown_edit.umd.min.js +3 -3
- package/dist/quikdown_edit.umd.min.js.gz +0 -0
- package/dist/quikdown_edit.umd.min.js.map +1 -1
- package/dist/quikdown_json.cjs +3 -3
- package/dist/quikdown_json.esm.js +3 -3
- package/dist/quikdown_json.esm.min.js +2 -2
- package/dist/quikdown_json.esm.min.js.gz +0 -0
- package/dist/quikdown_json.umd.js +3 -3
- package/dist/quikdown_json.umd.min.js +2 -2
- package/dist/quikdown_json.umd.min.js.gz +0 -0
- package/dist/quikdown_yaml.cjs +3 -3
- package/dist/quikdown_yaml.esm.js +3 -3
- package/dist/quikdown_yaml.esm.min.js +2 -2
- package/dist/quikdown_yaml.esm.min.js.gz +0 -0
- package/dist/quikdown_yaml.umd.js +3 -3
- package/dist/quikdown_yaml.umd.min.js +2 -2
- package/dist/quikdown_yaml.umd.min.js.gz +0 -0
- package/package.json +3 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* quikdown_bd - Bidirectional Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.7
|
|
4
4
|
* @license BSD-2-Clause
|
|
5
5
|
* @copyright DeftIO 2025
|
|
6
6
|
*/
|
|
7
|
-
!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_bd=t()}(this,function(){"use strict";const e="quikdown-",t="§CB",n={"&":"&","<":"<",">":">",'"':""","'":"'"},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,c={}){if(!o||"string"!=typeof o)return"";const{fence_plugin:l,inline_styles:i=!1,bidirectional:s=!1,lazy_linefeeds:d=!1}=c,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 f(e){return e.replace(/[&<>"']/g,e=>n[e])}const $=s?e=>` data-qd="${f(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 c=`${t}${h.length}§`,a=r?r.trim():"";return l&&l.render&&"function"==typeof l.render?h.push({lang:a,code:o.trimEnd(),custom:!0,fence:n,hasReverse:!!l.reverse}):h.push({lang:a,code:f(o.trimEnd()),custom:!1,fence:n}),c}),p=p.replace(/`([^`]+)`/g,(e,t)=>{const n=`§IC${m.length}§`;return m.push(f(t)),n}),p=f(p),p=function(e,t){const n=e.split("\n"),r=[];let o=!1,c=[];for(let e=0;e<n.length;e++){const l=n[e].trim();if(l.includes("|")&&(l.startsWith("|")||/[^\\|]/.test(l)))o||(o=!0,c=[]),c.push(l);else{if(o){const e=a(c,t);e?r.push(e):r.push(...c),o=!1,c=[]}r.push(n[e])}}if(o&&c.length>0){const e=a(c,t);e?r.push(e):r.push(...c)}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)}${$(t)}>${n}</h${r}>`}),p=p.replace(/^>\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 c=t.split("\n"),a=[],l=[],i=e=>e.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[e])),s=o?e=>` data-qd="${i(e)}"`:()=>"";for(let t=0;t<c.length;t++){const o=c[t],i=o.match(/^(\s*)([*\-+]|\d+\.)\s+(.+)$/);if(i){const[,t,o,c]=i,d=Math.floor(t.length/2),u=/^\d+\./.test(o),f=u?"ol":"ul";let $=c,g="";const p=c.match(/^\[([x ])\]\s+(.*)$/i);if(p&&!u){const[,t,n]=p,o="x"===t.toLowerCase();$=`<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();a.push(`</${e.type}>`)}if(l.length===d)l.push({type:f,level:d}),a.push(`<${f}${n(f)}>`);else if(l.length===d+1){const e=l[l.length-1];e.type!==f&&(a.push(`</${e.type}>`),l.pop(),l.push({type:f,level:d}),a.push(`<${f}${n(f)}>`))}const h=g||n("li");a.push(`<li${h}${s(o)}>${$}</li>`)}else{for(;l.length>0;){const e=l.pop();a.push(`</${e.type}>`)}a.push(o)}}for(;l.length>0;){const e=l.pop();a.push(`</${e.type}>`)}return a.join("\n")}(p,u,i,s),p=p.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(e,t,n)=>{const r=g(n,c.allow_unsafe_urls),o=s&&t?` data-qd-alt="${f(t)}"`:"",a=s?` data-qd-src="${f(n)}"`:"";return`<img${u("img")} src="${r}" alt="${t}"${o}${a}${$("!")}>`}),p=p.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>{const r=g(n,c.allow_unsafe_urls),o=/^https?:\/\//i.test(r)?' rel="noopener noreferrer"':"",a=s?` data-qd-text="${f(t)}"`:"";return`<a${u("a")} href="${r}"${o}${a}${$("[")}>${t}</a>`}),p=p.replace(/(^|\s)(https?:\/\/[^\s<]+)/g,(e,t,n)=>{const r=g(n,c.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)}${$(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(/ {2}$/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="${f(e.lang)}"`:"",c=s?` data-qd-fence="${f(e.fence)}"`:"";r=`<pre${u("pre")}${c}${o}><code${n}>${f(e.code)}</code></pre>`}else s&&(r=r.replace(/^<(\w+)/,`<$1 data-qd-fence="${f(e.fence)}" data-qd-lang="${f(e.lang)}" data-qd-source="${f(e.code)}"`));else{const t=!i&&e.lang?` class="language-${e.lang}"`:"",n=i?u("code"):t,o=s&&e.lang?` data-qd-lang="${f(e.lang)}"`:"",c=s?` data-qd-fence="${f(e.fence)}"`:"";r=`<pre${u("pre")}${c}${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")}${$("`")}>${e}</code>`)}),p.trim()}function c(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 a(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),a=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=a[n]&&"left"!==a[n]?`text-align:${a[n]}`:"",o=c(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=a[n]&&"left"!==a[n]?`text-align:${a[n]}`:"",o=c(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})}return o.emitStyles=function(e="quikdown-",t="light"){const n=r,o={"#f4f4f4":"#2a2a2a","#f0f0f0":"#2a2a2a","#f2f2f2":"#2a2a2a","#ddd":"#3a3a3a","#06c":"#6db3f2",_textColor:"#e0e0e0"},c={_textColor:"#333"};let a="";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&&c){["h1","h2","h3","h4","h5","h6","td","li","blockquote"].includes(r)&&(n+=`;color:${c._textColor}`)}a+=`.${e}${r} { ${n} }\n`}return a},o.configure=function(e){return function(t){return o(t,e)}},o.version="1.2.3","undefined"!=typeof module&&module.exports&&(module.exports=o),"undefined"!=typeof window&&(window.quikdown=o),Object.keys(o).forEach(e=>{"configure"!==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 c=e.tagName.toLowerCase(),a=e.getAttribute("data-qd");let l="";for(const t of e.childNodes)l+=r(t,{parentTag:c,...n});switch(c){case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":const n=parseInt(c[1]);return`${a||"#".repeat(n)} ${l.trim()}\n\n`;case"strong":case"b":if(!l)return"";const r=a||"**";return`${r}${l}${r}`;case"em":case"i":if(!l)return"";const i=a||"*";return`${i}${l}${i}`;case"del":case"s":case"strike":if(!l)return"";const s=a||"~~";return`${s}${l}${s}`;case"code":if(!l)return"";const d=a||"`";return`${d}${l}${d}`;case"pre":const u=e.getAttribute("data-qd-fence")||a||"```",f=e.getAttribute("data-qd-lang")||"";if(t.fence_plugin&&t.fence_plugin.reverse&&f)try{const n=t.fence_plugin.reverse(e);if(n&&n.content){const e=n.fence||u;return`${e}${n.lang||f}\n${n.content}\n${e}\n\n`}}catch(e){console.warn("Fence reverse handler error:",e)}const $=e.getAttribute("data-qd-source");if($)return`${u}${f}\n${$}\n${u}\n\n`;const g=e.querySelector("code");return`${u}${f}\n${(g?g.textContent:l).trimEnd()}\n${u}\n\n`;case"blockquote":const p=a||">";return l.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 h=e.getAttribute("data-qd-text")||l.trim(),m=e.getAttribute("href")||"";return h!==m||a?`[${h}](${m})`:`<${m}>`;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 o(e,"ol"===c)+"\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(const 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 c=e.querySelector("tbody");if(c)for(const e of c.querySelectorAll("tr")){const n=[];for(const 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 c=e.querySelector(".mermaid-source");if(c){const e=document.createElement("div");e.innerHTML=c.innerHTML;return`${t}${n}\n${e.textContent}\n${t}\n\n`}const a=e.querySelector(".mermaid");if(a&&a.textContent.includes("graph"))return`${t}${n}\n${a.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 c="",a=1;const l=" ".repeat(n);for(const i of e.children){if("LI"!==i.tagName)continue;let e=i.getAttribute("data-qd")||(t?`${a}.`:"-");const s=i.querySelector('input[type="checkbox"]');if(s){const t=s.checked?"x":" ";e="-";let n="";for(const e of i.childNodes)e.nodeType===Node.TEXT_NODE?n+=e.textContent:e.tagName&&"INPUT"!==e.tagName&&(n+=r(e));c+=`${l}${e} [${t}] ${n.trim()}\n`}else{let t="";for(const e of i.childNodes)"UL"===e.tagName||"OL"===e.tagName?t+=o(e,"OL"===e.tagName,n+1):t+=r(e);c+=`${l}${e} ${t.trim()}\n`}a++}return c}let c=r(n);return c=c.replace(/\n{3,}/g,"\n\n"),c=c.trim(),c},l.configure=function(e){const t=o.configure({...e,bidirectional:!0});return function(e){return t(e)}},"undefined"!=typeof module&&module.exports&&(module.exports=l),"undefined"!=typeof window&&(window.quikdown_bd=l),l});
|
|
7
|
+
!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_bd=t()}(this,function(){"use strict";const e="quikdown-",t="§CB",n={"&":"&","<":"<",">":">",'"':""","'":"'"},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,c={}){if(!o||"string"!=typeof o)return"";const{fence_plugin:l,inline_styles:i=!1,bidirectional:s=!1,lazy_linefeeds:d=!1,allow_unsafe_html:u=!1}=c,f=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 g=s?e=>` data-qd="${$(e)}"`:()=>"";function p(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 h=o;const m=[],b=[];h=h.replace(/^(```|~~~)([^\n]*)\n([\s\S]*?)^\1$/gm,(e,n,r,o)=>{const c=`${t}${m.length}§`,a=r?r.trim():"";return l&&l.render&&"function"==typeof l.render?m.push({lang:a,code:o.trimEnd(),custom:!0,fence:n,hasReverse:!!l.reverse}):m.push({lang:a,code:$(o.trimEnd()),custom:!1,fence:n}),c}),h=h.replace(/`([^`]+)`/g,(e,t)=>{const n=`§IC${b.length}§`;return b.push($(t)),n}),u||(h=$(h)),h=function(e,t){const n=e.split("\n"),r=[];let o=!1,c=[];for(let e=0;e<n.length;e++){const l=n[e].trim();if(l.includes("|")&&(l.startsWith("|")||/[^\\|]/.test(l)))o||(o=!0,c=[]),c.push(l);else{if(o){const e=a(c,t);e?r.push(e):r.push(...c),o=!1,c=[]}r.push(n[e])}}if(o&&c.length>0){const e=a(c,t);e?r.push(e):r.push(...c)}return r.join("\n")}(h,f),h=h.replace(/^(#{1,6})\s+(.+?)\s*#*$/gm,(e,t,n)=>{const r=t.length;return`<h${r}${f("h"+r)}${g(t)}>${n}</h${r}>`}),h=h.replace(/^>\s+(.+)$/gm,`<blockquote${f("blockquote")}>$1</blockquote>`),h=h.replace(/<\/blockquote>\n<blockquote>/g,"\n"),h=h.replace(/^---+\s*$/gm,`<hr${f("hr")}>`),h=function(t,n,r,o){const c=t.split("\n"),a=[],l=[],i=e=>e.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[e])),s=o?e=>` data-qd="${i(e)}"`:()=>"";for(let t=0;t<c.length;t++){const o=c[t],i=o.match(/^(\s*)([*\-+]|\d+\.)\s+(.+)$/);if(i){const[,t,o,c]=i,d=Math.floor(t.length/2),u=/^\d+\./.test(o),f=u?"ol":"ul";let $=c,g="";const p=c.match(/^\[([x ])\]\s+(.*)$/i);if(p&&!u){const[,t,n]=p,o="x"===t.toLowerCase();$=`<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();a.push(`</${e.type}>`)}if(l.length===d)l.push({type:f,level:d}),a.push(`<${f}${n(f)}>`);else if(l.length===d+1){const e=l[l.length-1];e.type!==f&&(a.push(`</${e.type}>`),l.pop(),l.push({type:f,level:d}),a.push(`<${f}${n(f)}>`))}const h=g||n("li");a.push(`<li${h}${s(o)}>${$}</li>`)}else{for(;l.length>0;){const e=l.pop();a.push(`</${e.type}>`)}a.push(o)}}for(;l.length>0;){const e=l.pop();a.push(`</${e.type}>`)}return a.join("\n")}(h,f,i,s),h=h.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(e,t,n)=>{const r=p(n,c.allow_unsafe_urls),o=s&&t?` data-qd-alt="${$(t)}"`:"",a=s?` data-qd-src="${$(n)}"`:"";return`<img${f("img")} src="${r}" alt="${t}"${o}${a}${g("!")}>`}),h=h.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>{const r=p(n,c.allow_unsafe_urls),o=/^https?:\/\//i.test(r)?' rel="noopener noreferrer"':"",a=s?` data-qd-text="${$(t)}"`:"";return`<a${f("a")} href="${r}"${o}${a}${g("[")}>${t}</a>`}),h=h.replace(/(^|\s)(https?:\/\/[^\s<]+)/g,(e,t,n)=>{const r=p(n,c.allow_unsafe_urls);return`${t}<a${f("a")} href="${r}" rel="noopener noreferrer">${n}</a>`});if([[/\*\*(.+?)\*\*/g,"strong","**"],[/__(.+?)__/g,"strong","__"],[/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g,"em","*"],[/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g,"em","_"],[/~~(.+?)~~/g,"del","~~"]].forEach(([e,t,n])=>{h=h.replace(e,`<${t}${f(t)}${g(n)}>$1</${t}>`)}),d){const e=[];let t=0;h=h.replace(/<(table|[uo]l)[^>]*>[\s\S]*?<\/\1>/g,n=>(e[t]=n,`§B${t++}§`)),h=h.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${f("br")}>`).replace(/§N§/g,"\n").replace(/§P§/g,"</p><p>"),e.forEach((e,t)=>h=h.replace(`§B${t}§`,e)),h="<p>"+h+"</p>"}else h=h.replace(/ {2}$/gm,`<br${f("br")}>`),h=h.replace(/\n\n+/g,(e,t)=>h.substring(0,t).match(/<\/(h[1-6]|blockquote|ul|ol|table|pre|hr)>$/)?"<p>":"</p><p>"),h="<p>"+h+"</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])=>{h=h.replace(e,t)}),h=h.replace(/(<\/(?:h[1-6]|blockquote|ul|ol|table|pre|hr)>)\n([^<])/g,"$1\n<p>$2"),m.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?f("code"):t,o=s&&e.lang?` data-qd-lang="${$(e.lang)}"`:"",c=s?` data-qd-fence="${$(e.fence)}"`:"";r=`<pre${f("pre")}${c}${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?f("code"):t,o=s&&e.lang?` data-qd-lang="${$(e.lang)}"`:"",c=s?` data-qd-fence="${$(e.fence)}"`:"";r=`<pre${f("pre")}${c}${o}><code${n}>${e.code}</code></pre>`}const o=`${t}${n}§`;h=h.replace(o,r)}),b.forEach((e,t)=>{const n=`§IC${t}§`;h=h.replace(n,`<code${f("code")}${g("`")}>${e}</code>`)}),h.trim()}function c(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 a(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),a=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=a[n]&&"left"!==a[n]?`text-align:${a[n]}`:"",o=c(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=a[n]&&"left"!==a[n]?`text-align:${a[n]}`:"",o=c(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})}return o.emitStyles=function(e="quikdown-",t="light"){const n=r,o={"#f4f4f4":"#2a2a2a","#f0f0f0":"#2a2a2a","#f2f2f2":"#2a2a2a","#ddd":"#3a3a3a","#06c":"#6db3f2",_textColor:"#e0e0e0"},c={_textColor:"#333"};let a="";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&&c){["h1","h2","h3","h4","h5","h6","td","li","blockquote"].includes(r)&&(n+=`;color:${c._textColor}`)}a+=`.${e}${r} { ${n} }\n`}return a},o.configure=function(e){return function(t){return o(t,e)}},o.version="1.2.7","undefined"!=typeof module&&module.exports&&(module.exports=o),"undefined"!=typeof window&&(window.quikdown=o),Object.keys(o).forEach(e=>{"configure"!==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 c=e.tagName.toLowerCase(),a=e.getAttribute("data-qd");let l="";for(const t of e.childNodes)l+=r(t,{parentTag:c,...n});switch(c){case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":const n=parseInt(c[1]);return`${a||"#".repeat(n)} ${l.trim()}\n\n`;case"strong":case"b":if(!l)return"";const r=a||"**";return`${r}${l}${r}`;case"em":case"i":if(!l)return"";const i=a||"*";return`${i}${l}${i}`;case"del":case"s":case"strike":if(!l)return"";const s=a||"~~";return`${s}${l}${s}`;case"code":if(!l)return"";const d=a||"`";return`${d}${l}${d}`;case"pre":const u=e.getAttribute("data-qd-fence")||a||"```",f=e.getAttribute("data-qd-lang")||"";if(t.fence_plugin&&t.fence_plugin.reverse&&f)try{const n=t.fence_plugin.reverse(e);if(n&&n.content){const e=n.fence||u;return`${e}${n.lang||f}\n${n.content}\n${e}\n\n`}}catch(e){console.warn("Fence reverse handler error:",e)}const $=e.getAttribute("data-qd-source");if($)return`${u}${f}\n${$}\n${u}\n\n`;const g=e.querySelector("code");return`${u}${f}\n${(g?g.textContent:l).trimEnd()}\n${u}\n\n`;case"blockquote":const p=a||">";return l.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 h=e.getAttribute("data-qd-text")||l.trim(),m=e.getAttribute("href")||"";return h!==m||a?`[${h}](${m})`:`<${m}>`;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 o(e,"ol"===c)+"\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(const 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 c=e.querySelector("tbody");if(c)for(const e of c.querySelectorAll("tr")){const n=[];for(const 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 c=e.querySelector(".mermaid-source");if(c){const e=document.createElement("div");e.innerHTML=c.innerHTML;return`${t}${n}\n${e.textContent}\n${t}\n\n`}const a=e.querySelector(".mermaid");if(a&&a.textContent.includes("graph"))return`${t}${n}\n${a.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 c="",a=1;const l=" ".repeat(n);for(const i of e.children){if("LI"!==i.tagName)continue;let e=i.getAttribute("data-qd")||(t?`${a}.`:"-");const s=i.querySelector('input[type="checkbox"]');if(s){const t=s.checked?"x":" ";e="-";let n="";for(const e of i.childNodes)e.nodeType===Node.TEXT_NODE?n+=e.textContent:e.tagName&&"INPUT"!==e.tagName&&(n+=r(e));c+=`${l}${e} [${t}] ${n.trim()}\n`}else{let t="";for(const e of i.childNodes)"UL"===e.tagName||"OL"===e.tagName?t+=o(e,"OL"===e.tagName,n+1):t+=r(e);c+=`${l}${e} ${t.trim()}\n`}a++}return c}let c=r(n);return c=c.replace(/\n{3,}/g,"\n\n"),c=c.trim(),c},l.configure=function(e){const t=o.configure({...e,bidirectional:!0});return function(e){return t(e)}},"undefined"!=typeof module&&module.exports&&(module.exports=l),"undefined"!=typeof window&&(window.quikdown_bd=l),l});
|
|
8
8
|
//# sourceMappingURL=quikdown_bd.umd.min.js.map
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quikdown_bd.umd.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 = {'&':'&','<':'<','>':'>','\"':'"',\"'\":'''};\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 // Ensure trailing semicolon before concatenating additionalStyle.\n // Both short-circuit paths of this guard (empty `style` or\n // already-has-`;`) are defensive and unreachable with the\n // current QUIKDOWN_STYLES values — istanbul ignore next.\n /* istanbul ignore next */\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 // The non-bidirectional branch is a trivial no-op arrow; it's exercised in\n // the core bundle but never in quikdown_bd (which always sets bidirectional=true).\n /* istanbul ignore next - trivial no-op fallback */\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(/^>\\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(/ {2}$/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 const listStack = []; // Track nested lists\n \n // Helper to escape HTML for data-qd attributes. List markers (`-`, `*`,\n // `+`, `1.`, etc.) never contain HTML-special chars, so the replace\n // callback is defensive-only and never actually fires in practice.\n const escapeHtml = (text) => text.replace(/[&<>\"']/g,\n /* istanbul ignore next - defensive: list markers never contain HTML specials */\n m => ({'&':'&','<':'<','>':'>','\"':'"',\"'\":'''})[m]);\n /* istanbul ignore next - trivial no-op fallback; not exercised via bd bundle */\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).\n// Skip `configure` — quikdown_bd provides its own override below, so the\n// inner quikdown.configure is dead code in this bundle.\nObject.keys(quikdown).forEach(key => {\n if (key === 'configure') return;\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 (const 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 ")\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 (const 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 (const 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 (const 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 (const 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 (const row of tbody.querySelectorAll('tr')) {\n const cells = [];\n for (const 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.\n// We delegate to the inner quikdown.configure so the shared closure\n// machinery is exercised in both bundles (no dead code).\nquikdown_bd.configure = function(options) {\n const innerParser = quikdown.configure({ ...options, bidirectional: true });\n return function(markdown) {\n return innerParser(markdown);\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","innerParser"],"mappings":";;;;;;2OAcA,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,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ASG,eAAe,IACpE,OAAO,SAASJ,GACZ,OAAOyM,EAAYzM,EACvB,CACJ,EAOsB,oBAAXkI,QAA0BA,OAAOC,UACxCD,OAAOC,QAAUd,GAIC,oBAAXe,SACPA,OAAOf,YAAcA"}
|
|
1
|
+
{"version":3,"file":"quikdown_bd.umd.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 = {'&':'&','<':'<','>':'>','\"':'"',\"'\":'''};\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 // Ensure trailing semicolon before concatenating additionalStyle.\n // Both short-circuit paths of this guard (empty `style` or\n // already-has-`;`) are defensive and unreachable with the\n // current QUIKDOWN_STYLES values — istanbul ignore next.\n /* istanbul ignore next */\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, allow_unsafe_html = 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 // The non-bidirectional branch is a trivial no-op arrow; it's exercised in\n // the core bundle but never in quikdown_bd (which always sets bidirectional=true).\n /* istanbul ignore next - trivial no-op fallback */\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 // Escape HTML in the rest of the content (skip if allow_unsafe_html is on —\n // useful for trusted pipelines where the markdown contains intentional HTML)\n if (!allow_unsafe_html) {\n html = escapeHtml(html);\n }\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(/^>\\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(/ {2}$/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 const listStack = []; // Track nested lists\n \n // Helper to escape HTML for data-qd attributes. List markers (`-`, `*`,\n // `+`, `1.`, etc.) never contain HTML-special chars, so the replace\n // callback is defensive-only and never actually fires in practice.\n const escapeHtml = (text) => text.replace(/[&<>\"']/g,\n /* istanbul ignore next - defensive: list markers never contain HTML specials */\n m => ({'&':'&','<':'<','>':'>','\"':'"',\"'\":'''})[m]);\n /* istanbul ignore next - trivial no-op fallback; not exercised via bd bundle */\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).\n// Skip `configure` — quikdown_bd provides its own override below, so the\n// inner quikdown.configure is dead code in this bundle.\nObject.keys(quikdown).forEach(key => {\n if (key === 'configure') return;\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 (const 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 ")\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 (const 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 (const 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 (const 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 (const 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 (const row of tbody.querySelectorAll('tr')) {\n const cells = [];\n for (const 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.\n// We delegate to the inner quikdown.configure so the shared closure\n// machinery is exercised in both bundles (no dead code).\nquikdown_bd.configure = function(options) {\n const innerParser = quikdown.configure({ ...options, bidirectional: true });\n return function(markdown) {\n return innerParser(markdown);\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","allow_unsafe_html","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","innerParser"],"mappings":";;;;;;2OAcA,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,qBAmCrB,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C,QAAUd,GAIC,oBAAXe,SACPA,OAAOf,YAAcA"}
|
package/dist/quikdown_edit.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Quikdown Editor - Drop-in Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.7
|
|
4
4
|
* @license BSD-2-Clause
|
|
5
5
|
* @copyright DeftIO 2025
|
|
6
6
|
*/
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
// Version will be injected at build time
|
|
23
|
-
const quikdownVersion = '1.2.
|
|
23
|
+
const quikdownVersion = '1.2.7';
|
|
24
24
|
|
|
25
25
|
// Constants for reuse
|
|
26
26
|
const CLASS_PREFIX = 'quikdown-';
|
|
@@ -95,7 +95,7 @@ function quikdown(markdown, options = {}) {
|
|
|
95
95
|
return '';
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
const { fence_plugin, inline_styles = false, bidirectional = false, lazy_linefeeds = false } = options;
|
|
98
|
+
const { fence_plugin, inline_styles = false, bidirectional = false, lazy_linefeeds = false, allow_unsafe_html = false } = options;
|
|
99
99
|
const styles = QUIKDOWN_STYLES; // Use module-level styles
|
|
100
100
|
const getAttr = createGetAttr(inline_styles, styles); // Create getAttr once
|
|
101
101
|
|
|
@@ -181,8 +181,11 @@ function quikdown(markdown, options = {}) {
|
|
|
181
181
|
return placeholder;
|
|
182
182
|
});
|
|
183
183
|
|
|
184
|
-
//
|
|
185
|
-
|
|
184
|
+
// Escape HTML in the rest of the content (skip if allow_unsafe_html is on —
|
|
185
|
+
// useful for trusted pipelines where the markdown contains intentional HTML)
|
|
186
|
+
if (!allow_unsafe_html) {
|
|
187
|
+
html = escapeHtml(html);
|
|
188
|
+
}
|
|
186
189
|
|
|
187
190
|
// Phase 2: Process block elements
|
|
188
191
|
|
|
@@ -2841,6 +2844,7 @@ class QuikdownEditor {
|
|
|
2841
2844
|
border-radius: 4px;
|
|
2842
2845
|
overflow: hidden;
|
|
2843
2846
|
background: white;
|
|
2847
|
+
color: #1f2937;
|
|
2844
2848
|
}
|
|
2845
2849
|
|
|
2846
2850
|
.qde-toolbar {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Quikdown Editor - Drop-in Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.7
|
|
4
4
|
* @license BSD-2-Clause
|
|
5
5
|
* @copyright DeftIO 2025
|
|
6
6
|
*/
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
// Version will be injected at build time
|
|
21
|
-
const quikdownVersion = '1.2.
|
|
21
|
+
const quikdownVersion = '1.2.7';
|
|
22
22
|
|
|
23
23
|
// Constants for reuse
|
|
24
24
|
const CLASS_PREFIX = 'quikdown-';
|
|
@@ -93,7 +93,7 @@ function quikdown(markdown, options = {}) {
|
|
|
93
93
|
return '';
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
const { fence_plugin, inline_styles = false, bidirectional = false, lazy_linefeeds = false } = options;
|
|
96
|
+
const { fence_plugin, inline_styles = false, bidirectional = false, lazy_linefeeds = false, allow_unsafe_html = false } = options;
|
|
97
97
|
const styles = QUIKDOWN_STYLES; // Use module-level styles
|
|
98
98
|
const getAttr = createGetAttr(inline_styles, styles); // Create getAttr once
|
|
99
99
|
|
|
@@ -179,8 +179,11 @@ function quikdown(markdown, options = {}) {
|
|
|
179
179
|
return placeholder;
|
|
180
180
|
});
|
|
181
181
|
|
|
182
|
-
//
|
|
183
|
-
|
|
182
|
+
// Escape HTML in the rest of the content (skip if allow_unsafe_html is on —
|
|
183
|
+
// useful for trusted pipelines where the markdown contains intentional HTML)
|
|
184
|
+
if (!allow_unsafe_html) {
|
|
185
|
+
html = escapeHtml(html);
|
|
186
|
+
}
|
|
184
187
|
|
|
185
188
|
// Phase 2: Process block elements
|
|
186
189
|
|
|
@@ -2839,6 +2842,7 @@ class QuikdownEditor {
|
|
|
2839
2842
|
border-radius: 4px;
|
|
2840
2843
|
overflow: hidden;
|
|
2841
2844
|
background: white;
|
|
2845
|
+
color: #1f2937;
|
|
2842
2846
|
}
|
|
2843
2847
|
|
|
2844
2848
|
.qde-toolbar {
|