quikdown 1.2.2 → 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.
Files changed (60) hide show
  1. package/README.md +22 -27
  2. package/dist/quikdown.cjs +25 -9
  3. package/dist/quikdown.dark.css +1 -1
  4. package/dist/quikdown.esm.js +25 -9
  5. package/dist/quikdown.esm.min.js +2 -2
  6. package/dist/quikdown.esm.min.js.gz +0 -0
  7. package/dist/quikdown.esm.min.js.map +1 -1
  8. package/dist/quikdown.light.css +1 -1
  9. package/dist/quikdown.umd.js +25 -9
  10. package/dist/quikdown.umd.min.js +2 -2
  11. package/dist/quikdown.umd.min.js.gz +0 -0
  12. package/dist/quikdown.umd.min.js.map +1 -1
  13. package/dist/quikdown_ast.cjs +2 -2
  14. package/dist/quikdown_ast.esm.js +2 -2
  15. package/dist/quikdown_ast.esm.min.js +2 -2
  16. package/dist/quikdown_ast.esm.min.js.gz +0 -0
  17. package/dist/quikdown_ast.umd.js +2 -2
  18. package/dist/quikdown_ast.umd.min.js +2 -2
  19. package/dist/quikdown_ast.umd.min.js.gz +0 -0
  20. package/dist/quikdown_ast_html.cjs +3 -3
  21. package/dist/quikdown_ast_html.esm.js +3 -3
  22. package/dist/quikdown_ast_html.esm.min.js +2 -2
  23. package/dist/quikdown_ast_html.esm.min.js.gz +0 -0
  24. package/dist/quikdown_ast_html.umd.js +3 -3
  25. package/dist/quikdown_ast_html.umd.min.js +2 -2
  26. package/dist/quikdown_ast_html.umd.min.js.gz +0 -0
  27. package/dist/quikdown_bd.cjs +34 -12
  28. package/dist/quikdown_bd.esm.js +34 -12
  29. package/dist/quikdown_bd.esm.min.js +2 -2
  30. package/dist/quikdown_bd.esm.min.js.gz +0 -0
  31. package/dist/quikdown_bd.esm.min.js.map +1 -1
  32. package/dist/quikdown_bd.umd.js +34 -12
  33. package/dist/quikdown_bd.umd.min.js +2 -2
  34. package/dist/quikdown_bd.umd.min.js.gz +0 -0
  35. package/dist/quikdown_bd.umd.min.js.map +1 -1
  36. package/dist/quikdown_edit.cjs +471 -124
  37. package/dist/quikdown_edit.d.ts +15 -1
  38. package/dist/quikdown_edit.esm.js +471 -124
  39. package/dist/quikdown_edit.esm.min.js +3 -3
  40. package/dist/quikdown_edit.esm.min.js.gz +0 -0
  41. package/dist/quikdown_edit.esm.min.js.map +1 -1
  42. package/dist/quikdown_edit.umd.js +471 -124
  43. package/dist/quikdown_edit.umd.min.js +3 -3
  44. package/dist/quikdown_edit.umd.min.js.gz +0 -0
  45. package/dist/quikdown_edit.umd.min.js.map +1 -1
  46. package/dist/quikdown_json.cjs +3 -3
  47. package/dist/quikdown_json.esm.js +3 -3
  48. package/dist/quikdown_json.esm.min.js +2 -2
  49. package/dist/quikdown_json.esm.min.js.gz +0 -0
  50. package/dist/quikdown_json.umd.js +3 -3
  51. package/dist/quikdown_json.umd.min.js +2 -2
  52. package/dist/quikdown_json.umd.min.js.gz +0 -0
  53. package/dist/quikdown_yaml.cjs +3 -3
  54. package/dist/quikdown_yaml.esm.js +3 -3
  55. package/dist/quikdown_yaml.esm.min.js +2 -2
  56. package/dist/quikdown_yaml.esm.min.js.gz +0 -0
  57. package/dist/quikdown_yaml.umd.js +3 -3
  58. package/dist/quikdown_yaml.umd.min.js +2 -2
  59. package/dist/quikdown_yaml.umd.min.js.gz +0 -0
  60. package/package.json +17 -14
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * quikdown_ast_html - AST to HTML Markdown Parser
3
- * @version 1.2.2
3
+ * @version 1.2.7
4
4
  * @license BSD-2-Clause
5
5
  * @copyright DeftIO 2025
6
6
  */
7
- function e(e,n={}){if(!e||"string"!=typeof e)return{type:"document",children:[]};return{type:"document",children:t(e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"))}}function t(e,r){const c=[],l=e.split("\n");let o=0;for(;o<l.length;){const e=l[o];if(""===e.trim()){o++;continue}const r=e.match(/^(```|~~~)(.*)$/);if(r){const[,e,t]=r,n=t.trim(),i=[];for(o++;o<l.length;){if(l[o].match(/^(```|~~~)\s*$/)){o++;break}i.push(l[o]),o++}c.push({type:"code_block",lang:n||null,content:i.join("\n"),fence:e});continue}if(/^---+\s*$/.test(e)||/^\*\*\*+\s*$/.test(e)||/^___+\s*$/.test(e)){c.push({type:"hr"}),o++;continue}const a=e.match(/^(#{1,6})\s*(.+?)\s*#*$/);if(a){const[,e,t]=a;c.push({type:"heading",level:e.length,children:s(t)}),o++;continue}if(e.includes("|")){const e=n(l,o);if(e){c.push(e.node),o=e.nextIndex;continue}}if(e.match(/^>\s*/)){const e=[];for(;o<l.length&&l[o].match(/^>\s*/);)e.push(l[o].replace(/^>\s*/,"")),o++;c.push({type:"blockquote",children:t(e.join("\n"))});continue}if(e.match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/)){const e=i(l,o);c.push(e.node),o=e.nextIndex;continue}const u=[];for(;o<l.length;){const e=l[o];if(""===e.trim())break;if(/^(```|~~~)/.test(e))break;if(/^#{1,6}\s/.test(e))break;if(/^---+\s*$/.test(e)||/^\*\*\*+\s*$/.test(e)||/^___+\s*$/.test(e))break;if(/^>\s*/.test(e))break;if(/^(\s*)([*\-+]|\d+\.)\s+/.test(e))break;if(e.includes("|")&&o+1<l.length&&/^\|?[\s\-:|]+\|?$/.test(l[o+1]))break;u.push(e),o++}u.length>0&&c.push({type:"paragraph",children:s(u.join("\n"))})}return c}function n(e,t,n){if(t+1>=e.length)return null;const i=e[t],c=e[t+1];if(!/^\|?[\s\-:|]+\|?$/.test(c)||!c.includes("-"))return null;const l=r(i);if(0===l.length)return null;const o=r(c).map(e=>{const t=e.trim();return t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left"}),a=l.map(e=>s(e.trim())),u=[];let h=t+2;for(;h<e.length;){const t=e[h];if(!t.includes("|")||""===t.trim())break;const n=r(t);u.push(n.map(e=>s(e.trim()))),h++}return{node:{type:"table",headers:a,rows:u,alignments:o},nextIndex:h}}function r(e){let t=e.trim();return t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&(t=t.slice(0,-1)),t.split("|")}function i(e,t,n){const r=[];let c=t,l=0;const o=e[c].match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/),a=/^\d+\./.test(o[2]),u=o[1].length;for(;c<e.length&&l<1e3;){l++;const t=e[c].match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/);if(!t)break;const[,n,o,h]=t,d=n.length;if(d<u)break;const f=/^\d+\./.test(o);if(d===u&&f!==a)break;if(d>u){const t=[];let n=0;for(;c<e.length&&n<1e3;){n++;const r=e[c],i=r.match(/^(\s*)([*\-+]|\d+\.)\s+/);if(!i)break;if(i[1].length<u)break;if(i[1].length===u)break;t.push(r),c++}if(t.length>0&&r.length>0){const e=i(t,0),n=r[r.length-1];n.children?Array.isArray(n.children)||(n.children=[{type:"paragraph",children:n.children}]):n.children=[],n.children.push(e.node)}continue}const p={type:"list_item",checked:null,children:null},m=h.match(/^\[([x ])\]\s*(.*)$/i);m&&!a?(p.checked="x"===m[1].toLowerCase(),p.children=s(m[2])):p.children=s(h),r.push(p),c++}return{node:{type:"list",ordered:a,items:r},nextIndex:c}}function s(e,t){if(!e)return[];const n=[];let r=e;for(;r.length>0;){let e=!1;if(r.match(/^(.+?)(?: {2}|\\\n|\n)/)&&r.includes("\n")){const t=r.indexOf("\n"),i=r.slice(0,t),s=r.slice(t+1);if(i.endsWith(" ")||i.endsWith("\\")){const t=i.replace(/\\$/,"").replace(/ +$/,"");t&&n.push(...c(t)),n.push({type:"br"}),r=s,e=!0;continue}}const t=r.match(/^!\[([^\]]*)\]\(\s*([^)\s]+)\s*\)/);if(t){n.push({type:"image",alt:t[1],url:t[2].trim()}),r=r.slice(t[0].length),e=!0;continue}const i=r.match(/^\[([^\]]+)\]\(\s*([^)\s]+)\s*\)/);if(i){n.push({type:"link",url:i[2].trim(),children:c(i[1])}),r=r.slice(i[0].length),e=!0;continue}const s=r.match(/^`([^`]+)`/);if(s){n.push({type:"code",value:s[1]}),r=r.slice(s[0].length),e=!0;continue}const l=r.match(/^(\*\*|__)(.+?)\1/);if(l){n.push({type:"strong",children:c(l[2])}),r=r.slice(l[0].length),e=!0;continue}const o=r.match(/^~~(.+?)~~/);if(o){n.push({type:"del",children:c(o[1])}),r=r.slice(o[0].length),e=!0;continue}const a=r.match(/^(\*|_)(?!\1)(.+?)(?<!\1)\1(?!\1)/);if(a){n.push({type:"em",children:c(a[2])}),r=r.slice(a[0].length),e=!0;continue}const u=r.match(/^(https?:\/\/[^\s<>[\]]+)/);if(u)n.push({type:"link",url:u[1],children:[{type:"text",value:u[1]}]}),r=r.slice(u[0].length),e=!0;else if(!e){const e=r.search(/[`*_~![\\n]|https?:\/\//);if(-1===e){n.push({type:"text",value:r});break}0===e?(n.push({type:"text",value:r[0]}),r=r.slice(1)):(n.push({type:"text",value:r.slice(0,e)}),r=r.slice(e))}}return function(e){const t=[];for(const n of e)"text"===n.type&&t.length>0&&"text"===t[t.length-1].type?t[t.length-1].value+=n.value:t.push(n);return t}(n)}function c(e,t){return s(e.replace(/\n/g," "))}e.version="1.2.2","undefined"!=typeof module&&module.exports&&(module.exports=e),"undefined"!=typeof window&&(window.quikdown_ast=e);const l="quikdown-",o={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},a={h1:"font-size:2em;font-weight:600;margin:.67em 0;text-align:left",h2:"font-size:1.5em;font-weight:600;margin:.83em 0",h3:"font-size:1.25em;font-weight:600;margin:1em 0",h4:"font-size:1em;font-weight:600;margin:1.33em 0",h5:"font-size:.875em;font-weight:600;margin:1.67em 0",h6:"font-size:.85em;font-weight:600;margin:2em 0",pre:"background:#f4f4f4;padding:10px;border-radius:4px;overflow-x:auto;margin:1em 0",code:"background:#f0f0f0;padding:2px 4px;border-radius:3px;font-family:monospace",blockquote:"border-left:4px solid #ddd;margin-left:0;padding-left:1em",table:"border-collapse:collapse;width:100%;margin:1em 0",th:"border:1px solid #ddd;padding:8px;background-color:#f2f2f2;font-weight:bold;text-align:left",td:"border:1px solid #ddd;padding:8px;text-align:left",hr:"border:none;border-top:1px solid #ddd;margin:1em 0",img:"max-width:100%;height:auto",a:"color:#06c;text-decoration:underline",strong:"font-weight:bold",em:"font-style:italic",del:"text-decoration:line-through",ul:"margin:.5em 0;padding-left:2em",ol:"margin:.5em 0;padding-left:2em",li:"margin:.25em 0","task-item":"list-style:none","task-checkbox":"margin-right:.5em"};function u(e){return e?String(e).replace(/[&<>"']/g,e=>o[e]):""}function h(e){if(!e)return"";const t=e.trim(),n=t.toLowerCase(),r=["javascript:","vbscript:","data:"];for(const e of r)if(n.startsWith(e))return"data:"===e&&n.startsWith("data:image/")?t:"#";return t}function d(t,n={}){if(!t)return{type:"document",children:[]};if("object"==typeof t&&t.type)return t;if("string"==typeof t){const r=t.trim();if(r.startsWith("{")||r.startsWith("["))try{const e=JSON.parse(r);return"document"===e.type?e:Array.isArray(e)?{type:"document",children:e}:e}catch(e){}if(r.includes("type:")&&(r.includes("children:")||r.includes("value:")))try{const e=f(r.split("\n"),0,0).value;if(e&&e.type)return e}catch(e){}return e(t,n)}return{type:"document",children:[]}}function f(e,t,n){if(t>=e.length)return{value:null,nextLine:t};const r=e[t],i=r.trim();if(""===i)return f(e,t+1,n);const s=r.search(/\S/);if(s<n&&s>=0)return{value:null,nextLine:t};if(i.startsWith("- "))return function(e,t,n){const r=[];let i=t;for(;i<e.length;){const t=e[i],s=t.trim();if(""===s){i++;continue}const c=t.search(/\S/);if(c<n&&c>=0)break;if(c>n&&r.length>0){i++;continue}if(!s.startsWith("- "))break;const l=s.slice(2);if(l.includes(":")){const t={},s=l.indexOf(":"),o=l.slice(0,s).trim(),a=l.slice(s+1).trim();if(""===a||a.startsWith("\n")){const n=f(e,i+1,c+2);t[o]=n.value,i=n.nextLine}else t[o]=p(a),i++;for(;i<e.length;){const r=e[i],s=r.trim();if(""===s){i++;continue}const c=r.search(/\S/);if(c<=n)break;if(s.startsWith("- "))break;const l=s.indexOf(":");if(l>0){const n=s.slice(0,l).trim(),r=s.slice(l+1).trim();if(""===r||r.startsWith("\n")){const r=f(e,i+1,c+2);t[n]=r.value,i=r.nextLine}else t[n]=p(r),i++}else i++}r.push(t)}else r.push(p(l)),i++}return{value:r,nextLine:i}}(e,t,s);if("[]"===i)return{value:[],nextLine:t+1};if("{}"===i)return{value:{},nextLine:t+1};return i.indexOf(":")>0?function(e,t,n){const r={};let i=t;for(;i<e.length;){const t=e[i],s=t.trim();if(""===s){i++;continue}const c=t.search(/\S/);if(c<n&&c>=0)break;const l=s.indexOf(":");if(l<=0){i++;continue}const o=s.slice(0,l).trim(),a=s.slice(l+1).trim();if(""===a||"|"===a||">"===a){const t=f(e,i+1,c+2);r[o]=t.value,i=t.nextLine}else r[o]=p(a),i++}return{value:r,nextLine:i}}(e,t,s):{value:p(i),nextLine:t+1}}function p(e){if(!e)return null;const t=e.trim();return"null"===t||"~"===t?null:"true"===t||"false"!==t&&(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1).replace(/\\n/g,"\n").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):/^-?\d+$/.test(t)?parseInt(t,10):/^-?\d+\.\d+$/.test(t)?parseFloat(t):t)}function m(e,t={}){return g(d(e,t),t)}function g(e,t={}){if(!e)return"";const{inline_styles:n=!1}=t,r=function(e){return function(t,n=""){if(e){let e=a[t];return e||n?(n&&n.includes("text-align")&&e&&e.includes("text-align")&&(e=e.replace(/text-align:[^;]+;?/,"").trim(),e&&!e.endsWith(";")&&(e+=";")),` style="${n?e?`${e}${n}`:n:e}"`):""}{const e=` class="${l}${t}"`;return n?`${e} style="${n}"`:e}}}(n);return $(e,r,t)}function $(e,t,n){if(!e)return"";switch(e.type){case"document":return y(e.children,t,n);case"paragraph":return`<p>${y(e.children,t,n)}</p>`;case"heading":const r=e.level||1;return`<h${r}${t("h"+r)}>${y(e.children,t,n)}</h${r}>`;case"code_block":const i=!n.inline_styles&&e.lang?` class="language-${e.lang}"`:"",s=n.inline_styles?t("code"):i;return`<pre${t("pre")}><code${s}>${u(e.content)}</code></pre>`;case"blockquote":return`<blockquote${t("blockquote")}>${y(e.children,t,n)}</blockquote>`;case"list":const c=e.ordered?"ol":"ul",o=(e.items||[]).map(e=>$(e,t,n)).join("");return`<${c}${t(c)}>${o}</${c}>`;case"list_item":if(null!==e.checked&&void 0!==e.checked){const r=n.inline_styles?' style="margin-right:.5em"':` class="${l}task-checkbox"`,i=e.checked?" checked":"";return`<li${n.inline_styles?' style="list-style:none"':` class="${l}task-item"`}><input type="checkbox"${r}${i} disabled> ${y(e.children,t,n)}</li>`}return`<li${t("li")}>${y(e.children,t,n)}</li>`;case"table":return function(e,t,n){const r=e.alignments||[];let i=`<table${t("table")}>\n`;e.headers&&e.headers.length>0&&(i+="<thead>\n<tr>\n",e.headers.forEach((e,s)=>{const c=r[s]&&"left"!==r[s]?`text-align:${r[s]}`:"";i+=`<th${t("th",c)}>${y(e,t,n)}</th>\n`}),i+="</tr>\n</thead>\n");e.rows&&e.rows.length>0&&(i+="<tbody>\n",e.rows.forEach(e=>{i+="<tr>\n",e.forEach((e,s)=>{const c=r[s]&&"left"!==r[s]?`text-align:${r[s]}`:"";i+=`<td${t("td",c)}>${y(e,t,n)}</td>\n`}),i+="</tr>\n"}),i+="</tbody>\n");return i+="</table>",i}(e,t,n);case"hr":return`<hr${t("hr")}>`;case"text":return u(e.value||"");case"strong":return`<strong${t("strong")}>${y(e.children,t,n)}</strong>`;case"em":return`<em${t("em")}>${y(e.children,t,n)}</em>`;case"del":return`<del${t("del")}>${y(e.children,t,n)}</del>`;case"code":return`<code${t("code")}>${u(e.value||"")}</code>`;case"link":const a=h(e.url),d=/^https?:\/\//i.test(a)?' rel="noopener noreferrer"':"";return`<a${t("a")} href="${a}"${d}>${y(e.children,t,n)}</a>`;case"image":const f=h(e.url);return`<img${t("img")} src="${f}" alt="${u(e.alt||"")}">`;case"br":return"<br>";default:return e.children?y(e.children,t,n):void 0!==e.value?u(String(e.value)):""}}function y(e,t,n){return e?Array.isArray(e)?e.map(e=>$(e,t,n)).join(""):$(e,t,n):""}m.toAst=d,m.renderAst=g,m.version="1.2.2","undefined"!=typeof module&&module.exports&&(module.exports=m),"undefined"!=typeof window&&(window.quikdown_ast_html=m);export{m as default};
7
+ function e(e,n={}){if(!e||"string"!=typeof e)return{type:"document",children:[]};return{type:"document",children:t(e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"))}}function t(e,r){const c=[],l=e.split("\n");let o=0;for(;o<l.length;){const e=l[o];if(""===e.trim()){o++;continue}const r=e.match(/^(```|~~~)(.*)$/);if(r){const[,e,t]=r,n=t.trim(),i=[];for(o++;o<l.length;){if(l[o].match(/^(```|~~~)\s*$/)){o++;break}i.push(l[o]),o++}c.push({type:"code_block",lang:n||null,content:i.join("\n"),fence:e});continue}if(/^---+\s*$/.test(e)||/^\*\*\*+\s*$/.test(e)||/^___+\s*$/.test(e)){c.push({type:"hr"}),o++;continue}const a=e.match(/^(#{1,6})\s*(.+?)\s*#*$/);if(a){const[,e,t]=a;c.push({type:"heading",level:e.length,children:s(t)}),o++;continue}if(e.includes("|")){const e=n(l,o);if(e){c.push(e.node),o=e.nextIndex;continue}}if(e.match(/^>\s*/)){const e=[];for(;o<l.length&&l[o].match(/^>\s*/);)e.push(l[o].replace(/^>\s*/,"")),o++;c.push({type:"blockquote",children:t(e.join("\n"))});continue}if(e.match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/)){const e=i(l,o);c.push(e.node),o=e.nextIndex;continue}const u=[];for(;o<l.length;){const e=l[o];if(""===e.trim())break;if(/^(```|~~~)/.test(e))break;if(/^#{1,6}\s/.test(e))break;if(/^---+\s*$/.test(e)||/^\*\*\*+\s*$/.test(e)||/^___+\s*$/.test(e))break;if(/^>\s*/.test(e))break;if(/^(\s*)([*\-+]|\d+\.)\s+/.test(e))break;if(e.includes("|")&&o+1<l.length&&/^\|?[\s\-:|]+\|?$/.test(l[o+1]))break;u.push(e),o++}u.length>0&&c.push({type:"paragraph",children:s(u.join("\n"))})}return c}function n(e,t,n){if(t+1>=e.length)return null;const i=e[t],c=e[t+1];if(!/^\|?[\s\-:|]+\|?$/.test(c)||!c.includes("-"))return null;const l=r(i);if(0===l.length)return null;const o=r(c).map(e=>{const t=e.trim();return t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left"}),a=l.map(e=>s(e.trim())),u=[];let h=t+2;for(;h<e.length;){const t=e[h];if(!t.includes("|")||""===t.trim())break;const n=r(t);u.push(n.map(e=>s(e.trim()))),h++}return{node:{type:"table",headers:a,rows:u,alignments:o},nextIndex:h}}function r(e){let t=e.trim();return t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&(t=t.slice(0,-1)),t.split("|")}function i(e,t,n){const r=[];let c=t,l=0;const o=e[c].match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/),a=/^\d+\./.test(o[2]),u=o[1].length;for(;c<e.length&&l<1e3;){l++;const t=e[c].match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/);if(!t)break;const[,n,o,h]=t,d=n.length;if(d<u)break;const f=/^\d+\./.test(o);if(d===u&&f!==a)break;if(d>u){const t=[];let n=0;for(;c<e.length&&n<1e3;){n++;const r=e[c],i=r.match(/^(\s*)([*\-+]|\d+\.)\s+/);if(!i)break;if(i[1].length<u)break;if(i[1].length===u)break;t.push(r),c++}if(t.length>0&&r.length>0){const e=i(t,0),n=r[r.length-1];n.children?Array.isArray(n.children)||(n.children=[{type:"paragraph",children:n.children}]):n.children=[],n.children.push(e.node)}continue}const p={type:"list_item",checked:null,children:null},m=h.match(/^\[([x ])\]\s*(.*)$/i);m&&!a?(p.checked="x"===m[1].toLowerCase(),p.children=s(m[2])):p.children=s(h),r.push(p),c++}return{node:{type:"list",ordered:a,items:r},nextIndex:c}}function s(e,t){if(!e)return[];const n=[];let r=e;for(;r.length>0;){let e=!1;if(r.match(/^(.+?)(?: {2}|\\\n|\n)/)&&r.includes("\n")){const t=r.indexOf("\n"),i=r.slice(0,t),s=r.slice(t+1);if(i.endsWith(" ")||i.endsWith("\\")){const t=i.replace(/\\$/,"").replace(/ +$/,"");t&&n.push(...c(t)),n.push({type:"br"}),r=s,e=!0;continue}}const t=r.match(/^!\[([^\]]*)\]\(\s*([^)\s]+)\s*\)/);if(t){n.push({type:"image",alt:t[1],url:t[2].trim()}),r=r.slice(t[0].length),e=!0;continue}const i=r.match(/^\[([^\]]+)\]\(\s*([^)\s]+)\s*\)/);if(i){n.push({type:"link",url:i[2].trim(),children:c(i[1])}),r=r.slice(i[0].length),e=!0;continue}const s=r.match(/^`([^`]+)`/);if(s){n.push({type:"code",value:s[1]}),r=r.slice(s[0].length),e=!0;continue}const l=r.match(/^(\*\*|__)(.+?)\1/);if(l){n.push({type:"strong",children:c(l[2])}),r=r.slice(l[0].length),e=!0;continue}const o=r.match(/^~~(.+?)~~/);if(o){n.push({type:"del",children:c(o[1])}),r=r.slice(o[0].length),e=!0;continue}const a=r.match(/^(\*|_)(?!\1)(.+?)(?<!\1)\1(?!\1)/);if(a){n.push({type:"em",children:c(a[2])}),r=r.slice(a[0].length),e=!0;continue}const u=r.match(/^(https?:\/\/[^\s<>[\]]+)/);if(u)n.push({type:"link",url:u[1],children:[{type:"text",value:u[1]}]}),r=r.slice(u[0].length),e=!0;else if(!e){const e=r.search(/[`*_~![\\n]|https?:\/\//);if(-1===e){n.push({type:"text",value:r});break}0===e?(n.push({type:"text",value:r[0]}),r=r.slice(1)):(n.push({type:"text",value:r.slice(0,e)}),r=r.slice(e))}}return function(e){const t=[];for(const n of e)"text"===n.type&&t.length>0&&"text"===t[t.length-1].type?t[t.length-1].value+=n.value:t.push(n);return t}(n)}function c(e,t){return s(e.replace(/\n/g," "))}e.version="1.2.7","undefined"!=typeof module&&module.exports&&(module.exports=e),"undefined"!=typeof window&&(window.quikdown_ast=e);const l="quikdown-",o={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},a={h1:"font-size:2em;font-weight:600;margin:.67em 0;text-align:left",h2:"font-size:1.5em;font-weight:600;margin:.83em 0",h3:"font-size:1.25em;font-weight:600;margin:1em 0",h4:"font-size:1em;font-weight:600;margin:1.33em 0",h5:"font-size:.875em;font-weight:600;margin:1.67em 0",h6:"font-size:.85em;font-weight:600;margin:2em 0",pre:"background:#f4f4f4;padding:10px;border-radius:4px;overflow-x:auto;margin:1em 0",code:"background:#f0f0f0;padding:2px 4px;border-radius:3px;font-family:monospace",blockquote:"border-left:4px solid #ddd;margin-left:0;padding-left:1em",table:"border-collapse:collapse;width:100%;margin:1em 0",th:"border:1px solid #ddd;padding:8px;background-color:#f2f2f2;font-weight:bold;text-align:left",td:"border:1px solid #ddd;padding:8px;text-align:left",hr:"border:none;border-top:1px solid #ddd;margin:1em 0",img:"max-width:100%;height:auto",a:"color:#06c;text-decoration:underline",strong:"font-weight:bold",em:"font-style:italic",del:"text-decoration:line-through",ul:"margin:.5em 0;padding-left:2em",ol:"margin:.5em 0;padding-left:2em",li:"margin:.25em 0","task-item":"list-style:none","task-checkbox":"margin-right:.5em"};function u(e){return e?String(e).replace(/[&<>"']/g,e=>o[e]):""}function h(e){if(!e)return"";const t=e.trim(),n=t.toLowerCase(),r=["javascript:","vbscript:","data:"];for(const e of r)if(n.startsWith(e))return"data:"===e&&n.startsWith("data:image/")?t:"#";return t}function d(t,n={}){if(!t)return{type:"document",children:[]};if("object"==typeof t&&t.type)return t;if("string"==typeof t){const r=t.trim();if(r.startsWith("{")||r.startsWith("["))try{const e=JSON.parse(r);return"document"===e.type?e:Array.isArray(e)?{type:"document",children:e}:e}catch(e){}if(r.includes("type:")&&(r.includes("children:")||r.includes("value:")))try{const e=f(r.split("\n"),0,0).value;if(e&&e.type)return e}catch(e){}return e(t,n)}return{type:"document",children:[]}}function f(e,t,n){if(t>=e.length)return{value:null,nextLine:t};const r=e[t],i=r.trim();if(""===i)return f(e,t+1,n);const s=r.search(/\S/);if(s<n&&s>=0)return{value:null,nextLine:t};if(i.startsWith("- "))return function(e,t,n){const r=[];let i=t;for(;i<e.length;){const t=e[i],s=t.trim();if(""===s){i++;continue}const c=t.search(/\S/);if(c<n&&c>=0)break;if(c>n&&r.length>0){i++;continue}if(!s.startsWith("- "))break;const l=s.slice(2);if(l.includes(":")){const t={},s=l.indexOf(":"),o=l.slice(0,s).trim(),a=l.slice(s+1).trim();if(""===a||a.startsWith("\n")){const n=f(e,i+1,c+2);t[o]=n.value,i=n.nextLine}else t[o]=p(a),i++;for(;i<e.length;){const r=e[i],s=r.trim();if(""===s){i++;continue}const c=r.search(/\S/);if(c<=n)break;if(s.startsWith("- "))break;const l=s.indexOf(":");if(l>0){const n=s.slice(0,l).trim(),r=s.slice(l+1).trim();if(""===r||r.startsWith("\n")){const r=f(e,i+1,c+2);t[n]=r.value,i=r.nextLine}else t[n]=p(r),i++}else i++}r.push(t)}else r.push(p(l)),i++}return{value:r,nextLine:i}}(e,t,s);if("[]"===i)return{value:[],nextLine:t+1};if("{}"===i)return{value:{},nextLine:t+1};return i.indexOf(":")>0?function(e,t,n){const r={};let i=t;for(;i<e.length;){const t=e[i],s=t.trim();if(""===s){i++;continue}const c=t.search(/\S/);if(c<n&&c>=0)break;const l=s.indexOf(":");if(l<=0){i++;continue}const o=s.slice(0,l).trim(),a=s.slice(l+1).trim();if(""===a||"|"===a||">"===a){const t=f(e,i+1,c+2);r[o]=t.value,i=t.nextLine}else r[o]=p(a),i++}return{value:r,nextLine:i}}(e,t,s):{value:p(i),nextLine:t+1}}function p(e){if(!e)return null;const t=e.trim();return"null"===t||"~"===t?null:"true"===t||"false"!==t&&(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1).replace(/\\n/g,"\n").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):/^-?\d+$/.test(t)?parseInt(t,10):/^-?\d+\.\d+$/.test(t)?parseFloat(t):t)}function m(e,t={}){return g(d(e,t),t)}function g(e,t={}){if(!e)return"";const{inline_styles:n=!1}=t,r=function(e){return function(t,n=""){if(e){let e=a[t];return e||n?(n&&n.includes("text-align")&&e&&e.includes("text-align")&&(e=e.replace(/text-align:[^;]+;?/,"").trim(),e&&!e.endsWith(";")&&(e+=";")),` style="${n?e?`${e}${n}`:n:e}"`):""}{const e=` class="${l}${t}"`;return n?`${e} style="${n}"`:e}}}(n);return $(e,r,t)}function $(e,t,n){if(!e)return"";switch(e.type){case"document":return y(e.children,t,n);case"paragraph":return`<p>${y(e.children,t,n)}</p>`;case"heading":const r=e.level||1;return`<h${r}${t("h"+r)}>${y(e.children,t,n)}</h${r}>`;case"code_block":const i=!n.inline_styles&&e.lang?` class="language-${e.lang}"`:"",s=n.inline_styles?t("code"):i;return`<pre${t("pre")}><code${s}>${u(e.content)}</code></pre>`;case"blockquote":return`<blockquote${t("blockquote")}>${y(e.children,t,n)}</blockquote>`;case"list":const c=e.ordered?"ol":"ul",o=(e.items||[]).map(e=>$(e,t,n)).join("");return`<${c}${t(c)}>${o}</${c}>`;case"list_item":if(null!==e.checked&&void 0!==e.checked){const r=n.inline_styles?' style="margin-right:.5em"':` class="${l}task-checkbox"`,i=e.checked?" checked":"";return`<li${n.inline_styles?' style="list-style:none"':` class="${l}task-item"`}><input type="checkbox"${r}${i} disabled> ${y(e.children,t,n)}</li>`}return`<li${t("li")}>${y(e.children,t,n)}</li>`;case"table":return function(e,t,n){const r=e.alignments||[];let i=`<table${t("table")}>\n`;e.headers&&e.headers.length>0&&(i+="<thead>\n<tr>\n",e.headers.forEach((e,s)=>{const c=r[s]&&"left"!==r[s]?`text-align:${r[s]}`:"";i+=`<th${t("th",c)}>${y(e,t,n)}</th>\n`}),i+="</tr>\n</thead>\n");e.rows&&e.rows.length>0&&(i+="<tbody>\n",e.rows.forEach(e=>{i+="<tr>\n",e.forEach((e,s)=>{const c=r[s]&&"left"!==r[s]?`text-align:${r[s]}`:"";i+=`<td${t("td",c)}>${y(e,t,n)}</td>\n`}),i+="</tr>\n"}),i+="</tbody>\n");return i+="</table>",i}(e,t,n);case"hr":return`<hr${t("hr")}>`;case"text":return u(e.value||"");case"strong":return`<strong${t("strong")}>${y(e.children,t,n)}</strong>`;case"em":return`<em${t("em")}>${y(e.children,t,n)}</em>`;case"del":return`<del${t("del")}>${y(e.children,t,n)}</del>`;case"code":return`<code${t("code")}>${u(e.value||"")}</code>`;case"link":const a=h(e.url),d=/^https?:\/\//i.test(a)?' rel="noopener noreferrer"':"";return`<a${t("a")} href="${a}"${d}>${y(e.children,t,n)}</a>`;case"image":const f=h(e.url);return`<img${t("img")} src="${f}" alt="${u(e.alt||"")}">`;case"br":return"<br>";default:return e.children?y(e.children,t,n):void 0!==e.value?u(String(e.value)):""}}function y(e,t,n){return e?Array.isArray(e)?e.map(e=>$(e,t,n)).join(""):$(e,t,n):""}m.toAst=d,m.renderAst=g,m.version="1.2.7","undefined"!=typeof module&&module.exports&&(module.exports=m),"undefined"!=typeof window&&(window.quikdown_ast_html=m);export{m as default};
8
8
  //# sourceMappingURL=quikdown_ast_html.esm.min.js.map
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * quikdown_ast_html - AST to HTML Markdown Parser
3
- * @version 1.2.2
3
+ * @version 1.2.7
4
4
  * @license BSD-2-Clause
5
5
  * @copyright DeftIO 2025
6
6
  */
@@ -19,7 +19,7 @@
19
19
  */
20
20
 
21
21
  // Version will be injected at build time
22
- const quikdownVersion$1 = '1.2.2';
22
+ const quikdownVersion$1 = '1.2.7';
23
23
 
24
24
  // Safety limit to prevent infinite loops in list parsing
25
25
  const MAX_LOOP_ITERATIONS = 1000;
@@ -524,7 +524,7 @@
524
524
 
525
525
 
526
526
  // Version will be injected at build time
527
- const quikdownVersion = '1.2.2';
527
+ const quikdownVersion = '1.2.7';
528
528
 
529
529
  // Constants
530
530
  const CLASS_PREFIX = 'quikdown-';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * quikdown_ast_html - AST to HTML Markdown Parser
3
- * @version 1.2.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_ast_html=t()}(this,function(){"use strict";function e(e,n={}){if(!e||"string"!=typeof e)return{type:"document",children:[]};return{type:"document",children:t(e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"))}}function t(e,i){const c=[],l=e.split("\n");let o=0;for(;o<l.length;){const e=l[o];if(""===e.trim()){o++;continue}const i=e.match(/^(```|~~~)(.*)$/);if(i){const[,e,t]=i,n=t.trim(),r=[];for(o++;o<l.length;){if(l[o].match(/^(```|~~~)\s*$/)){o++;break}r.push(l[o]),o++}c.push({type:"code_block",lang:n||null,content:r.join("\n"),fence:e});continue}if(/^---+\s*$/.test(e)||/^\*\*\*+\s*$/.test(e)||/^___+\s*$/.test(e)){c.push({type:"hr"}),o++;continue}const a=e.match(/^(#{1,6})\s*(.+?)\s*#*$/);if(a){const[,e,t]=a;c.push({type:"heading",level:e.length,children:s(t)}),o++;continue}if(e.includes("|")){const e=n(l,o);if(e){c.push(e.node),o=e.nextIndex;continue}}if(e.match(/^>\s*/)){const e=[];for(;o<l.length&&l[o].match(/^>\s*/);)e.push(l[o].replace(/^>\s*/,"")),o++;c.push({type:"blockquote",children:t(e.join("\n"))});continue}if(e.match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/)){const e=r(l,o);c.push(e.node),o=e.nextIndex;continue}const u=[];for(;o<l.length;){const e=l[o];if(""===e.trim())break;if(/^(```|~~~)/.test(e))break;if(/^#{1,6}\s/.test(e))break;if(/^---+\s*$/.test(e)||/^\*\*\*+\s*$/.test(e)||/^___+\s*$/.test(e))break;if(/^>\s*/.test(e))break;if(/^(\s*)([*\-+]|\d+\.)\s+/.test(e))break;if(e.includes("|")&&o+1<l.length&&/^\|?[\s\-:|]+\|?$/.test(l[o+1]))break;u.push(e),o++}u.length>0&&c.push({type:"paragraph",children:s(u.join("\n"))})}return c}function n(e,t,n){if(t+1>=e.length)return null;const r=e[t],c=e[t+1];if(!/^\|?[\s\-:|]+\|?$/.test(c)||!c.includes("-"))return null;const l=i(r);if(0===l.length)return null;const o=i(c).map(e=>{const t=e.trim();return t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left"}),a=l.map(e=>s(e.trim())),u=[];let d=t+2;for(;d<e.length;){const t=e[d];if(!t.includes("|")||""===t.trim())break;const n=i(t);u.push(n.map(e=>s(e.trim()))),d++}return{node:{type:"table",headers:a,rows:u,alignments:o},nextIndex:d}}function i(e){let t=e.trim();return t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&(t=t.slice(0,-1)),t.split("|")}function r(e,t,n){const i=[];let c=t,l=0;const o=e[c].match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/),a=/^\d+\./.test(o[2]),u=o[1].length;for(;c<e.length&&l<1e3;){l++;const t=e[c].match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/);if(!t)break;const[,n,o,d]=t,h=n.length;if(h<u)break;const f=/^\d+\./.test(o);if(h===u&&f!==a)break;if(h>u){const t=[];let n=0;for(;c<e.length&&n<1e3;){n++;const i=e[c],r=i.match(/^(\s*)([*\-+]|\d+\.)\s+/);if(!r)break;if(r[1].length<u)break;if(r[1].length===u)break;t.push(i),c++}if(t.length>0&&i.length>0){const e=r(t,0),n=i[i.length-1];n.children?Array.isArray(n.children)||(n.children=[{type:"paragraph",children:n.children}]):n.children=[],n.children.push(e.node)}continue}const p={type:"list_item",checked:null,children:null},m=d.match(/^\[([x ])\]\s*(.*)$/i);m&&!a?(p.checked="x"===m[1].toLowerCase(),p.children=s(m[2])):p.children=s(d),i.push(p),c++}return{node:{type:"list",ordered:a,items:i},nextIndex:c}}function s(e,t){if(!e)return[];const n=[];let i=e;for(;i.length>0;){let e=!1;if(i.match(/^(.+?)(?: {2}|\\\n|\n)/)&&i.includes("\n")){const t=i.indexOf("\n"),r=i.slice(0,t),s=i.slice(t+1);if(r.endsWith(" ")||r.endsWith("\\")){const t=r.replace(/\\$/,"").replace(/ +$/,"");t&&n.push(...c(t)),n.push({type:"br"}),i=s,e=!0;continue}}const t=i.match(/^!\[([^\]]*)\]\(\s*([^)\s]+)\s*\)/);if(t){n.push({type:"image",alt:t[1],url:t[2].trim()}),i=i.slice(t[0].length),e=!0;continue}const r=i.match(/^\[([^\]]+)\]\(\s*([^)\s]+)\s*\)/);if(r){n.push({type:"link",url:r[2].trim(),children:c(r[1])}),i=i.slice(r[0].length),e=!0;continue}const s=i.match(/^`([^`]+)`/);if(s){n.push({type:"code",value:s[1]}),i=i.slice(s[0].length),e=!0;continue}const l=i.match(/^(\*\*|__)(.+?)\1/);if(l){n.push({type:"strong",children:c(l[2])}),i=i.slice(l[0].length),e=!0;continue}const o=i.match(/^~~(.+?)~~/);if(o){n.push({type:"del",children:c(o[1])}),i=i.slice(o[0].length),e=!0;continue}const a=i.match(/^(\*|_)(?!\1)(.+?)(?<!\1)\1(?!\1)/);if(a){n.push({type:"em",children:c(a[2])}),i=i.slice(a[0].length),e=!0;continue}const u=i.match(/^(https?:\/\/[^\s<>[\]]+)/);if(u)n.push({type:"link",url:u[1],children:[{type:"text",value:u[1]}]}),i=i.slice(u[0].length),e=!0;else if(!e){const e=i.search(/[`*_~![\\n]|https?:\/\//);if(-1===e){n.push({type:"text",value:i});break}0===e?(n.push({type:"text",value:i[0]}),i=i.slice(1)):(n.push({type:"text",value:i.slice(0,e)}),i=i.slice(e))}}return function(e){const t=[];for(const n of e)"text"===n.type&&t.length>0&&"text"===t[t.length-1].type?t[t.length-1].value+=n.value:t.push(n);return t}(n)}function c(e,t){return s(e.replace(/\n/g," "))}e.version="1.2.2","undefined"!=typeof module&&module.exports&&(module.exports=e),"undefined"!=typeof window&&(window.quikdown_ast=e);const l="quikdown-",o={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},a={h1:"font-size:2em;font-weight:600;margin:.67em 0;text-align:left",h2:"font-size:1.5em;font-weight:600;margin:.83em 0",h3:"font-size:1.25em;font-weight:600;margin:1em 0",h4:"font-size:1em;font-weight:600;margin:1.33em 0",h5:"font-size:.875em;font-weight:600;margin:1.67em 0",h6:"font-size:.85em;font-weight:600;margin:2em 0",pre:"background:#f4f4f4;padding:10px;border-radius:4px;overflow-x:auto;margin:1em 0",code:"background:#f0f0f0;padding:2px 4px;border-radius:3px;font-family:monospace",blockquote:"border-left:4px solid #ddd;margin-left:0;padding-left:1em",table:"border-collapse:collapse;width:100%;margin:1em 0",th:"border:1px solid #ddd;padding:8px;background-color:#f2f2f2;font-weight:bold;text-align:left",td:"border:1px solid #ddd;padding:8px;text-align:left",hr:"border:none;border-top:1px solid #ddd;margin:1em 0",img:"max-width:100%;height:auto",a:"color:#06c;text-decoration:underline",strong:"font-weight:bold",em:"font-style:italic",del:"text-decoration:line-through",ul:"margin:.5em 0;padding-left:2em",ol:"margin:.5em 0;padding-left:2em",li:"margin:.25em 0","task-item":"list-style:none","task-checkbox":"margin-right:.5em"};function u(e){return e?String(e).replace(/[&<>"']/g,e=>o[e]):""}function d(e){if(!e)return"";const t=e.trim(),n=t.toLowerCase(),i=["javascript:","vbscript:","data:"];for(const e of i)if(n.startsWith(e))return"data:"===e&&n.startsWith("data:image/")?t:"#";return t}function h(t,n={}){if(!t)return{type:"document",children:[]};if("object"==typeof t&&t.type)return t;if("string"==typeof t){const i=t.trim();if(i.startsWith("{")||i.startsWith("["))try{const e=JSON.parse(i);return"document"===e.type?e:Array.isArray(e)?{type:"document",children:e}:e}catch(e){}if(i.includes("type:")&&(i.includes("children:")||i.includes("value:")))try{const e=f(i.split("\n"),0,0).value;if(e&&e.type)return e}catch(e){}return e(t,n)}return{type:"document",children:[]}}function f(e,t,n){if(t>=e.length)return{value:null,nextLine:t};const i=e[t],r=i.trim();if(""===r)return f(e,t+1,n);const s=i.search(/\S/);if(s<n&&s>=0)return{value:null,nextLine:t};if(r.startsWith("- "))return function(e,t,n){const i=[];let r=t;for(;r<e.length;){const t=e[r],s=t.trim();if(""===s){r++;continue}const c=t.search(/\S/);if(c<n&&c>=0)break;if(c>n&&i.length>0){r++;continue}if(!s.startsWith("- "))break;const l=s.slice(2);if(l.includes(":")){const t={},s=l.indexOf(":"),o=l.slice(0,s).trim(),a=l.slice(s+1).trim();if(""===a||a.startsWith("\n")){const n=f(e,r+1,c+2);t[o]=n.value,r=n.nextLine}else t[o]=p(a),r++;for(;r<e.length;){const i=e[r],s=i.trim();if(""===s){r++;continue}const c=i.search(/\S/);if(c<=n)break;if(s.startsWith("- "))break;const l=s.indexOf(":");if(l>0){const n=s.slice(0,l).trim(),i=s.slice(l+1).trim();if(""===i||i.startsWith("\n")){const i=f(e,r+1,c+2);t[n]=i.value,r=i.nextLine}else t[n]=p(i),r++}else r++}i.push(t)}else i.push(p(l)),r++}return{value:i,nextLine:r}}(e,t,s);if("[]"===r)return{value:[],nextLine:t+1};if("{}"===r)return{value:{},nextLine:t+1};return r.indexOf(":")>0?function(e,t,n){const i={};let r=t;for(;r<e.length;){const t=e[r],s=t.trim();if(""===s){r++;continue}const c=t.search(/\S/);if(c<n&&c>=0)break;const l=s.indexOf(":");if(l<=0){r++;continue}const o=s.slice(0,l).trim(),a=s.slice(l+1).trim();if(""===a||"|"===a||">"===a){const t=f(e,r+1,c+2);i[o]=t.value,r=t.nextLine}else i[o]=p(a),r++}return{value:i,nextLine:r}}(e,t,s):{value:p(r),nextLine:t+1}}function p(e){if(!e)return null;const t=e.trim();return"null"===t||"~"===t?null:"true"===t||"false"!==t&&(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1).replace(/\\n/g,"\n").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):/^-?\d+$/.test(t)?parseInt(t,10):/^-?\d+\.\d+$/.test(t)?parseFloat(t):t)}function m(e,t={}){return g(h(e,t),t)}function g(e,t={}){if(!e)return"";const{inline_styles:n=!1}=t,i=function(e){return function(t,n=""){if(e){let e=a[t];return e||n?(n&&n.includes("text-align")&&e&&e.includes("text-align")&&(e=e.replace(/text-align:[^;]+;?/,"").trim(),e&&!e.endsWith(";")&&(e+=";")),` style="${n?e?`${e}${n}`:n:e}"`):""}{const e=` class="${l}${t}"`;return n?`${e} style="${n}"`:e}}}(n);return $(e,i,t)}function $(e,t,n){if(!e)return"";switch(e.type){case"document":return y(e.children,t,n);case"paragraph":return`<p>${y(e.children,t,n)}</p>`;case"heading":const i=e.level||1;return`<h${i}${t("h"+i)}>${y(e.children,t,n)}</h${i}>`;case"code_block":const r=!n.inline_styles&&e.lang?` class="language-${e.lang}"`:"",s=n.inline_styles?t("code"):r;return`<pre${t("pre")}><code${s}>${u(e.content)}</code></pre>`;case"blockquote":return`<blockquote${t("blockquote")}>${y(e.children,t,n)}</blockquote>`;case"list":const c=e.ordered?"ol":"ul",o=(e.items||[]).map(e=>$(e,t,n)).join("");return`<${c}${t(c)}>${o}</${c}>`;case"list_item":if(null!==e.checked&&void 0!==e.checked){const i=n.inline_styles?' style="margin-right:.5em"':` class="${l}task-checkbox"`,r=e.checked?" checked":"";return`<li${n.inline_styles?' style="list-style:none"':` class="${l}task-item"`}><input type="checkbox"${i}${r} disabled> ${y(e.children,t,n)}</li>`}return`<li${t("li")}>${y(e.children,t,n)}</li>`;case"table":return function(e,t,n){const i=e.alignments||[];let r=`<table${t("table")}>\n`;e.headers&&e.headers.length>0&&(r+="<thead>\n<tr>\n",e.headers.forEach((e,s)=>{const c=i[s]&&"left"!==i[s]?`text-align:${i[s]}`:"";r+=`<th${t("th",c)}>${y(e,t,n)}</th>\n`}),r+="</tr>\n</thead>\n");e.rows&&e.rows.length>0&&(r+="<tbody>\n",e.rows.forEach(e=>{r+="<tr>\n",e.forEach((e,s)=>{const c=i[s]&&"left"!==i[s]?`text-align:${i[s]}`:"";r+=`<td${t("td",c)}>${y(e,t,n)}</td>\n`}),r+="</tr>\n"}),r+="</tbody>\n");return r+="</table>",r}(e,t,n);case"hr":return`<hr${t("hr")}>`;case"text":return u(e.value||"");case"strong":return`<strong${t("strong")}>${y(e.children,t,n)}</strong>`;case"em":return`<em${t("em")}>${y(e.children,t,n)}</em>`;case"del":return`<del${t("del")}>${y(e.children,t,n)}</del>`;case"code":return`<code${t("code")}>${u(e.value||"")}</code>`;case"link":const a=d(e.url),h=/^https?:\/\//i.test(a)?' rel="noopener noreferrer"':"";return`<a${t("a")} href="${a}"${h}>${y(e.children,t,n)}</a>`;case"image":const f=d(e.url);return`<img${t("img")} src="${f}" alt="${u(e.alt||"")}">`;case"br":return"<br>";default:return e.children?y(e.children,t,n):void 0!==e.value?u(String(e.value)):""}}function y(e,t,n){return e?Array.isArray(e)?e.map(e=>$(e,t,n)).join(""):$(e,t,n):""}return m.toAst=h,m.renderAst=g,m.version="1.2.2","undefined"!=typeof module&&module.exports&&(module.exports=m),"undefined"!=typeof window&&(window.quikdown_ast_html=m),m});
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_ast_html=t()}(this,function(){"use strict";function e(e,n={}){if(!e||"string"!=typeof e)return{type:"document",children:[]};return{type:"document",children:t(e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"))}}function t(e,i){const c=[],l=e.split("\n");let o=0;for(;o<l.length;){const e=l[o];if(""===e.trim()){o++;continue}const i=e.match(/^(```|~~~)(.*)$/);if(i){const[,e,t]=i,n=t.trim(),r=[];for(o++;o<l.length;){if(l[o].match(/^(```|~~~)\s*$/)){o++;break}r.push(l[o]),o++}c.push({type:"code_block",lang:n||null,content:r.join("\n"),fence:e});continue}if(/^---+\s*$/.test(e)||/^\*\*\*+\s*$/.test(e)||/^___+\s*$/.test(e)){c.push({type:"hr"}),o++;continue}const a=e.match(/^(#{1,6})\s*(.+?)\s*#*$/);if(a){const[,e,t]=a;c.push({type:"heading",level:e.length,children:s(t)}),o++;continue}if(e.includes("|")){const e=n(l,o);if(e){c.push(e.node),o=e.nextIndex;continue}}if(e.match(/^>\s*/)){const e=[];for(;o<l.length&&l[o].match(/^>\s*/);)e.push(l[o].replace(/^>\s*/,"")),o++;c.push({type:"blockquote",children:t(e.join("\n"))});continue}if(e.match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/)){const e=r(l,o);c.push(e.node),o=e.nextIndex;continue}const u=[];for(;o<l.length;){const e=l[o];if(""===e.trim())break;if(/^(```|~~~)/.test(e))break;if(/^#{1,6}\s/.test(e))break;if(/^---+\s*$/.test(e)||/^\*\*\*+\s*$/.test(e)||/^___+\s*$/.test(e))break;if(/^>\s*/.test(e))break;if(/^(\s*)([*\-+]|\d+\.)\s+/.test(e))break;if(e.includes("|")&&o+1<l.length&&/^\|?[\s\-:|]+\|?$/.test(l[o+1]))break;u.push(e),o++}u.length>0&&c.push({type:"paragraph",children:s(u.join("\n"))})}return c}function n(e,t,n){if(t+1>=e.length)return null;const r=e[t],c=e[t+1];if(!/^\|?[\s\-:|]+\|?$/.test(c)||!c.includes("-"))return null;const l=i(r);if(0===l.length)return null;const o=i(c).map(e=>{const t=e.trim();return t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left"}),a=l.map(e=>s(e.trim())),u=[];let d=t+2;for(;d<e.length;){const t=e[d];if(!t.includes("|")||""===t.trim())break;const n=i(t);u.push(n.map(e=>s(e.trim()))),d++}return{node:{type:"table",headers:a,rows:u,alignments:o},nextIndex:d}}function i(e){let t=e.trim();return t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&(t=t.slice(0,-1)),t.split("|")}function r(e,t,n){const i=[];let c=t,l=0;const o=e[c].match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/),a=/^\d+\./.test(o[2]),u=o[1].length;for(;c<e.length&&l<1e3;){l++;const t=e[c].match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/);if(!t)break;const[,n,o,d]=t,h=n.length;if(h<u)break;const f=/^\d+\./.test(o);if(h===u&&f!==a)break;if(h>u){const t=[];let n=0;for(;c<e.length&&n<1e3;){n++;const i=e[c],r=i.match(/^(\s*)([*\-+]|\d+\.)\s+/);if(!r)break;if(r[1].length<u)break;if(r[1].length===u)break;t.push(i),c++}if(t.length>0&&i.length>0){const e=r(t,0),n=i[i.length-1];n.children?Array.isArray(n.children)||(n.children=[{type:"paragraph",children:n.children}]):n.children=[],n.children.push(e.node)}continue}const p={type:"list_item",checked:null,children:null},m=d.match(/^\[([x ])\]\s*(.*)$/i);m&&!a?(p.checked="x"===m[1].toLowerCase(),p.children=s(m[2])):p.children=s(d),i.push(p),c++}return{node:{type:"list",ordered:a,items:i},nextIndex:c}}function s(e,t){if(!e)return[];const n=[];let i=e;for(;i.length>0;){let e=!1;if(i.match(/^(.+?)(?: {2}|\\\n|\n)/)&&i.includes("\n")){const t=i.indexOf("\n"),r=i.slice(0,t),s=i.slice(t+1);if(r.endsWith(" ")||r.endsWith("\\")){const t=r.replace(/\\$/,"").replace(/ +$/,"");t&&n.push(...c(t)),n.push({type:"br"}),i=s,e=!0;continue}}const t=i.match(/^!\[([^\]]*)\]\(\s*([^)\s]+)\s*\)/);if(t){n.push({type:"image",alt:t[1],url:t[2].trim()}),i=i.slice(t[0].length),e=!0;continue}const r=i.match(/^\[([^\]]+)\]\(\s*([^)\s]+)\s*\)/);if(r){n.push({type:"link",url:r[2].trim(),children:c(r[1])}),i=i.slice(r[0].length),e=!0;continue}const s=i.match(/^`([^`]+)`/);if(s){n.push({type:"code",value:s[1]}),i=i.slice(s[0].length),e=!0;continue}const l=i.match(/^(\*\*|__)(.+?)\1/);if(l){n.push({type:"strong",children:c(l[2])}),i=i.slice(l[0].length),e=!0;continue}const o=i.match(/^~~(.+?)~~/);if(o){n.push({type:"del",children:c(o[1])}),i=i.slice(o[0].length),e=!0;continue}const a=i.match(/^(\*|_)(?!\1)(.+?)(?<!\1)\1(?!\1)/);if(a){n.push({type:"em",children:c(a[2])}),i=i.slice(a[0].length),e=!0;continue}const u=i.match(/^(https?:\/\/[^\s<>[\]]+)/);if(u)n.push({type:"link",url:u[1],children:[{type:"text",value:u[1]}]}),i=i.slice(u[0].length),e=!0;else if(!e){const e=i.search(/[`*_~![\\n]|https?:\/\//);if(-1===e){n.push({type:"text",value:i});break}0===e?(n.push({type:"text",value:i[0]}),i=i.slice(1)):(n.push({type:"text",value:i.slice(0,e)}),i=i.slice(e))}}return function(e){const t=[];for(const n of e)"text"===n.type&&t.length>0&&"text"===t[t.length-1].type?t[t.length-1].value+=n.value:t.push(n);return t}(n)}function c(e,t){return s(e.replace(/\n/g," "))}e.version="1.2.7","undefined"!=typeof module&&module.exports&&(module.exports=e),"undefined"!=typeof window&&(window.quikdown_ast=e);const l="quikdown-",o={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},a={h1:"font-size:2em;font-weight:600;margin:.67em 0;text-align:left",h2:"font-size:1.5em;font-weight:600;margin:.83em 0",h3:"font-size:1.25em;font-weight:600;margin:1em 0",h4:"font-size:1em;font-weight:600;margin:1.33em 0",h5:"font-size:.875em;font-weight:600;margin:1.67em 0",h6:"font-size:.85em;font-weight:600;margin:2em 0",pre:"background:#f4f4f4;padding:10px;border-radius:4px;overflow-x:auto;margin:1em 0",code:"background:#f0f0f0;padding:2px 4px;border-radius:3px;font-family:monospace",blockquote:"border-left:4px solid #ddd;margin-left:0;padding-left:1em",table:"border-collapse:collapse;width:100%;margin:1em 0",th:"border:1px solid #ddd;padding:8px;background-color:#f2f2f2;font-weight:bold;text-align:left",td:"border:1px solid #ddd;padding:8px;text-align:left",hr:"border:none;border-top:1px solid #ddd;margin:1em 0",img:"max-width:100%;height:auto",a:"color:#06c;text-decoration:underline",strong:"font-weight:bold",em:"font-style:italic",del:"text-decoration:line-through",ul:"margin:.5em 0;padding-left:2em",ol:"margin:.5em 0;padding-left:2em",li:"margin:.25em 0","task-item":"list-style:none","task-checkbox":"margin-right:.5em"};function u(e){return e?String(e).replace(/[&<>"']/g,e=>o[e]):""}function d(e){if(!e)return"";const t=e.trim(),n=t.toLowerCase(),i=["javascript:","vbscript:","data:"];for(const e of i)if(n.startsWith(e))return"data:"===e&&n.startsWith("data:image/")?t:"#";return t}function h(t,n={}){if(!t)return{type:"document",children:[]};if("object"==typeof t&&t.type)return t;if("string"==typeof t){const i=t.trim();if(i.startsWith("{")||i.startsWith("["))try{const e=JSON.parse(i);return"document"===e.type?e:Array.isArray(e)?{type:"document",children:e}:e}catch(e){}if(i.includes("type:")&&(i.includes("children:")||i.includes("value:")))try{const e=f(i.split("\n"),0,0).value;if(e&&e.type)return e}catch(e){}return e(t,n)}return{type:"document",children:[]}}function f(e,t,n){if(t>=e.length)return{value:null,nextLine:t};const i=e[t],r=i.trim();if(""===r)return f(e,t+1,n);const s=i.search(/\S/);if(s<n&&s>=0)return{value:null,nextLine:t};if(r.startsWith("- "))return function(e,t,n){const i=[];let r=t;for(;r<e.length;){const t=e[r],s=t.trim();if(""===s){r++;continue}const c=t.search(/\S/);if(c<n&&c>=0)break;if(c>n&&i.length>0){r++;continue}if(!s.startsWith("- "))break;const l=s.slice(2);if(l.includes(":")){const t={},s=l.indexOf(":"),o=l.slice(0,s).trim(),a=l.slice(s+1).trim();if(""===a||a.startsWith("\n")){const n=f(e,r+1,c+2);t[o]=n.value,r=n.nextLine}else t[o]=p(a),r++;for(;r<e.length;){const i=e[r],s=i.trim();if(""===s){r++;continue}const c=i.search(/\S/);if(c<=n)break;if(s.startsWith("- "))break;const l=s.indexOf(":");if(l>0){const n=s.slice(0,l).trim(),i=s.slice(l+1).trim();if(""===i||i.startsWith("\n")){const i=f(e,r+1,c+2);t[n]=i.value,r=i.nextLine}else t[n]=p(i),r++}else r++}i.push(t)}else i.push(p(l)),r++}return{value:i,nextLine:r}}(e,t,s);if("[]"===r)return{value:[],nextLine:t+1};if("{}"===r)return{value:{},nextLine:t+1};return r.indexOf(":")>0?function(e,t,n){const i={};let r=t;for(;r<e.length;){const t=e[r],s=t.trim();if(""===s){r++;continue}const c=t.search(/\S/);if(c<n&&c>=0)break;const l=s.indexOf(":");if(l<=0){r++;continue}const o=s.slice(0,l).trim(),a=s.slice(l+1).trim();if(""===a||"|"===a||">"===a){const t=f(e,r+1,c+2);i[o]=t.value,r=t.nextLine}else i[o]=p(a),r++}return{value:i,nextLine:r}}(e,t,s):{value:p(r),nextLine:t+1}}function p(e){if(!e)return null;const t=e.trim();return"null"===t||"~"===t?null:"true"===t||"false"!==t&&(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1).replace(/\\n/g,"\n").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):/^-?\d+$/.test(t)?parseInt(t,10):/^-?\d+\.\d+$/.test(t)?parseFloat(t):t)}function m(e,t={}){return g(h(e,t),t)}function g(e,t={}){if(!e)return"";const{inline_styles:n=!1}=t,i=function(e){return function(t,n=""){if(e){let e=a[t];return e||n?(n&&n.includes("text-align")&&e&&e.includes("text-align")&&(e=e.replace(/text-align:[^;]+;?/,"").trim(),e&&!e.endsWith(";")&&(e+=";")),` style="${n?e?`${e}${n}`:n:e}"`):""}{const e=` class="${l}${t}"`;return n?`${e} style="${n}"`:e}}}(n);return $(e,i,t)}function $(e,t,n){if(!e)return"";switch(e.type){case"document":return y(e.children,t,n);case"paragraph":return`<p>${y(e.children,t,n)}</p>`;case"heading":const i=e.level||1;return`<h${i}${t("h"+i)}>${y(e.children,t,n)}</h${i}>`;case"code_block":const r=!n.inline_styles&&e.lang?` class="language-${e.lang}"`:"",s=n.inline_styles?t("code"):r;return`<pre${t("pre")}><code${s}>${u(e.content)}</code></pre>`;case"blockquote":return`<blockquote${t("blockquote")}>${y(e.children,t,n)}</blockquote>`;case"list":const c=e.ordered?"ol":"ul",o=(e.items||[]).map(e=>$(e,t,n)).join("");return`<${c}${t(c)}>${o}</${c}>`;case"list_item":if(null!==e.checked&&void 0!==e.checked){const i=n.inline_styles?' style="margin-right:.5em"':` class="${l}task-checkbox"`,r=e.checked?" checked":"";return`<li${n.inline_styles?' style="list-style:none"':` class="${l}task-item"`}><input type="checkbox"${i}${r} disabled> ${y(e.children,t,n)}</li>`}return`<li${t("li")}>${y(e.children,t,n)}</li>`;case"table":return function(e,t,n){const i=e.alignments||[];let r=`<table${t("table")}>\n`;e.headers&&e.headers.length>0&&(r+="<thead>\n<tr>\n",e.headers.forEach((e,s)=>{const c=i[s]&&"left"!==i[s]?`text-align:${i[s]}`:"";r+=`<th${t("th",c)}>${y(e,t,n)}</th>\n`}),r+="</tr>\n</thead>\n");e.rows&&e.rows.length>0&&(r+="<tbody>\n",e.rows.forEach(e=>{r+="<tr>\n",e.forEach((e,s)=>{const c=i[s]&&"left"!==i[s]?`text-align:${i[s]}`:"";r+=`<td${t("td",c)}>${y(e,t,n)}</td>\n`}),r+="</tr>\n"}),r+="</tbody>\n");return r+="</table>",r}(e,t,n);case"hr":return`<hr${t("hr")}>`;case"text":return u(e.value||"");case"strong":return`<strong${t("strong")}>${y(e.children,t,n)}</strong>`;case"em":return`<em${t("em")}>${y(e.children,t,n)}</em>`;case"del":return`<del${t("del")}>${y(e.children,t,n)}</del>`;case"code":return`<code${t("code")}>${u(e.value||"")}</code>`;case"link":const a=d(e.url),h=/^https?:\/\//i.test(a)?' rel="noopener noreferrer"':"";return`<a${t("a")} href="${a}"${h}>${y(e.children,t,n)}</a>`;case"image":const f=d(e.url);return`<img${t("img")} src="${f}" alt="${u(e.alt||"")}">`;case"br":return"<br>";default:return e.children?y(e.children,t,n):void 0!==e.value?u(String(e.value)):""}}function y(e,t,n){return e?Array.isArray(e)?e.map(e=>$(e,t,n)).join(""):$(e,t,n):""}return m.toAst=h,m.renderAst=g,m.version="1.2.7","undefined"!=typeof module&&module.exports&&(module.exports=m),"undefined"!=typeof window&&(window.quikdown_ast_html=m),m});
8
8
  //# sourceMappingURL=quikdown_ast_html.umd.min.js.map
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * quikdown_bd - Bidirectional Markdown Parser
3
- * @version 1.2.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.2';
23
+ const quikdownVersion = '1.2.7';
24
24
 
25
25
  // Constants for reuse
26
26
  const CLASS_PREFIX = 'quikdown-';
@@ -68,6 +68,11 @@ function createGetAttr(inline_styles, styles) {
68
68
  // Remove default text-align if we're adding a different alignment
69
69
  if (additionalStyle && additionalStyle.includes('text-align') && style && style.includes('text-align')) {
70
70
  style = style.replace(/text-align:[^;]+;?/, '').trim();
71
+ // Ensure trailing semicolon before concatenating additionalStyle.
72
+ // Both short-circuit paths of this guard (empty `style` or
73
+ // already-has-`;`) are defensive and unreachable with the
74
+ // current QUIKDOWN_STYLES values — istanbul ignore next.
75
+ /* istanbul ignore next */
71
76
  if (style && !style.endsWith(';')) style += ';';
72
77
  }
73
78
 
@@ -90,7 +95,7 @@ function quikdown(markdown, options = {}) {
90
95
  return '';
91
96
  }
92
97
 
93
- 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;
94
99
  const styles = QUIKDOWN_STYLES; // Use module-level styles
95
100
  const getAttr = createGetAttr(inline_styles, styles); // Create getAttr once
96
101
 
@@ -99,9 +104,12 @@ function quikdown(markdown, options = {}) {
99
104
  return text.replace(/[&<>"']/g, m => ESC_MAP[m]);
100
105
  }
101
106
 
102
- // Helper to add data-qd attributes for bidirectional support
107
+ // Helper to add data-qd attributes for bidirectional support.
108
+ // The non-bidirectional branch is a trivial no-op arrow; it's exercised in
109
+ // the core bundle but never in quikdown_bd (which always sets bidirectional=true).
110
+ /* istanbul ignore next - trivial no-op fallback */
103
111
  const dataQd = bidirectional ? (marker) => ` data-qd="${escapeHtml(marker)}"` : () => '';
104
-
112
+
105
113
  // Sanitize URLs to prevent XSS attacks
106
114
  function sanitizeUrl(url, allowUnsafe = false) {
107
115
  /* istanbul ignore next - defensive programming, regex ensures url is never empty */
@@ -173,8 +181,11 @@ function quikdown(markdown, options = {}) {
173
181
  return placeholder;
174
182
  });
175
183
 
176
- // Now escape HTML in the rest of the content
177
- html = escapeHtml(html);
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
+ }
178
189
 
179
190
  // Phase 2: Process block elements
180
191
 
@@ -507,8 +518,13 @@ function processLists(text, getAttr, inline_styles, bidirectional) {
507
518
  const result = [];
508
519
  const listStack = []; // Track nested lists
509
520
 
510
- // Helper to escape HTML for data-qd attributes
511
- const escapeHtml = (text) => text.replace(/[&<>"']/g, m => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'})[m]);
521
+ // Helper to escape HTML for data-qd attributes. List markers (`-`, `*`,
522
+ // `+`, `1.`, etc.) never contain HTML-special chars, so the replace
523
+ // callback is defensive-only and never actually fires in practice.
524
+ const escapeHtml = (text) => text.replace(/[&<>"']/g,
525
+ /* istanbul ignore next - defensive: list markers never contain HTML specials */
526
+ m => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'})[m]);
527
+ /* istanbul ignore next - trivial no-op fallback; not exercised via bd bundle */
512
528
  const dataQd = bidirectional ? (marker) => ` data-qd="${escapeHtml(marker)}"` : () => '';
513
529
 
514
530
  for (let i = 0; i < lines.length; i++) {
@@ -680,8 +696,11 @@ function quikdown_bd(markdown, options = {}) {
680
696
  return quikdown(markdown, { ...options, bidirectional: true });
681
697
  }
682
698
 
683
- // Copy all properties and methods from quikdown (including version)
699
+ // Copy all properties and methods from quikdown (including version).
700
+ // Skip `configure` — quikdown_bd provides its own override below, so the
701
+ // inner quikdown.configure is dead code in this bundle.
684
702
  Object.keys(quikdown).forEach(key => {
703
+ if (key === 'configure') return;
685
704
  quikdown_bd[key] = quikdown[key];
686
705
  });
687
706
 
@@ -1045,10 +1064,13 @@ quikdown_bd.toMarkdown = function(htmlOrElement, options = {}) {
1045
1064
  return markdown;
1046
1065
  };
1047
1066
 
1048
- // Override the configure method to return a bidirectional version
1067
+ // Override the configure method to return a bidirectional version.
1068
+ // We delegate to the inner quikdown.configure so the shared closure
1069
+ // machinery is exercised in both bundles (no dead code).
1049
1070
  quikdown_bd.configure = function(options) {
1071
+ const innerParser = quikdown.configure({ ...options, bidirectional: true });
1050
1072
  return function(markdown) {
1051
- return quikdown_bd(markdown, options);
1073
+ return innerParser(markdown);
1052
1074
  };
1053
1075
  };
1054
1076
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * quikdown_bd - Bidirectional Markdown Parser
3
- * @version 1.2.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.2';
21
+ const quikdownVersion = '1.2.7';
22
22
 
23
23
  // Constants for reuse
24
24
  const CLASS_PREFIX = 'quikdown-';
@@ -66,6 +66,11 @@ function createGetAttr(inline_styles, styles) {
66
66
  // Remove default text-align if we're adding a different alignment
67
67
  if (additionalStyle && additionalStyle.includes('text-align') && style && style.includes('text-align')) {
68
68
  style = style.replace(/text-align:[^;]+;?/, '').trim();
69
+ // Ensure trailing semicolon before concatenating additionalStyle.
70
+ // Both short-circuit paths of this guard (empty `style` or
71
+ // already-has-`;`) are defensive and unreachable with the
72
+ // current QUIKDOWN_STYLES values — istanbul ignore next.
73
+ /* istanbul ignore next */
69
74
  if (style && !style.endsWith(';')) style += ';';
70
75
  }
71
76
 
@@ -88,7 +93,7 @@ function quikdown(markdown, options = {}) {
88
93
  return '';
89
94
  }
90
95
 
91
- 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;
92
97
  const styles = QUIKDOWN_STYLES; // Use module-level styles
93
98
  const getAttr = createGetAttr(inline_styles, styles); // Create getAttr once
94
99
 
@@ -97,9 +102,12 @@ function quikdown(markdown, options = {}) {
97
102
  return text.replace(/[&<>"']/g, m => ESC_MAP[m]);
98
103
  }
99
104
 
100
- // Helper to add data-qd attributes for bidirectional support
105
+ // Helper to add data-qd attributes for bidirectional support.
106
+ // The non-bidirectional branch is a trivial no-op arrow; it's exercised in
107
+ // the core bundle but never in quikdown_bd (which always sets bidirectional=true).
108
+ /* istanbul ignore next - trivial no-op fallback */
101
109
  const dataQd = bidirectional ? (marker) => ` data-qd="${escapeHtml(marker)}"` : () => '';
102
-
110
+
103
111
  // Sanitize URLs to prevent XSS attacks
104
112
  function sanitizeUrl(url, allowUnsafe = false) {
105
113
  /* istanbul ignore next - defensive programming, regex ensures url is never empty */
@@ -171,8 +179,11 @@ function quikdown(markdown, options = {}) {
171
179
  return placeholder;
172
180
  });
173
181
 
174
- // Now escape HTML in the rest of the content
175
- html = escapeHtml(html);
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
+ }
176
187
 
177
188
  // Phase 2: Process block elements
178
189
 
@@ -505,8 +516,13 @@ function processLists(text, getAttr, inline_styles, bidirectional) {
505
516
  const result = [];
506
517
  const listStack = []; // Track nested lists
507
518
 
508
- // Helper to escape HTML for data-qd attributes
509
- const escapeHtml = (text) => text.replace(/[&<>"']/g, m => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'})[m]);
519
+ // Helper to escape HTML for data-qd attributes. List markers (`-`, `*`,
520
+ // `+`, `1.`, etc.) never contain HTML-special chars, so the replace
521
+ // callback is defensive-only and never actually fires in practice.
522
+ const escapeHtml = (text) => text.replace(/[&<>"']/g,
523
+ /* istanbul ignore next - defensive: list markers never contain HTML specials */
524
+ m => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'})[m]);
525
+ /* istanbul ignore next - trivial no-op fallback; not exercised via bd bundle */
510
526
  const dataQd = bidirectional ? (marker) => ` data-qd="${escapeHtml(marker)}"` : () => '';
511
527
 
512
528
  for (let i = 0; i < lines.length; i++) {
@@ -678,8 +694,11 @@ function quikdown_bd(markdown, options = {}) {
678
694
  return quikdown(markdown, { ...options, bidirectional: true });
679
695
  }
680
696
 
681
- // Copy all properties and methods from quikdown (including version)
697
+ // Copy all properties and methods from quikdown (including version).
698
+ // Skip `configure` — quikdown_bd provides its own override below, so the
699
+ // inner quikdown.configure is dead code in this bundle.
682
700
  Object.keys(quikdown).forEach(key => {
701
+ if (key === 'configure') return;
683
702
  quikdown_bd[key] = quikdown[key];
684
703
  });
685
704
 
@@ -1043,10 +1062,13 @@ quikdown_bd.toMarkdown = function(htmlOrElement, options = {}) {
1043
1062
  return markdown;
1044
1063
  };
1045
1064
 
1046
- // Override the configure method to return a bidirectional version
1065
+ // Override the configure method to return a bidirectional version.
1066
+ // We delegate to the inner quikdown.configure so the shared closure
1067
+ // machinery is exercised in both bundles (no dead code).
1047
1068
  quikdown_bd.configure = function(options) {
1069
+ const innerParser = quikdown.configure({ ...options, bidirectional: true });
1048
1070
  return function(markdown) {
1049
- return quikdown_bd(markdown, options);
1071
+ return innerParser(markdown);
1050
1072
  };
1051
1073
  };
1052
1074
 
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * quikdown_bd - Bidirectional Markdown Parser
3
- * @version 1.2.2
3
+ * @version 1.2.7
4
4
  * @license BSD-2-Clause
5
5
  * @copyright DeftIO 2025
6
6
  */
7
- const e="quikdown-",t="§CB",n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},r={h1:"font-size:2em;font-weight:600;margin:.67em 0;text-align:left",h2:"font-size:1.5em;font-weight:600;margin:.83em 0",h3:"font-size:1.25em;font-weight:600;margin:1em 0",h4:"font-size:1em;font-weight:600;margin:1.33em 0",h5:"font-size:.875em;font-weight:600;margin:1.67em 0",h6:"font-size:.85em;font-weight:600;margin:2em 0",pre:"background:#f4f4f4;padding:10px;border-radius:4px;overflow-x:auto;margin:1em 0",code:"background:#f0f0f0;padding:2px 4px;border-radius:3px;font-family:monospace",blockquote:"border-left:4px solid #ddd;margin-left:0;padding-left:1em",table:"border-collapse:collapse;width:100%;margin:1em 0",th:"border:1px solid #ddd;padding:8px;background-color:#f2f2f2;font-weight:bold;text-align:left",td:"border:1px solid #ddd;padding:8px;text-align:left",hr:"border:none;border-top:1px solid #ddd;margin:1em 0",img:"max-width:100%;height:auto",a:"color:#06c;text-decoration:underline",strong:"font-weight:bold",em:"font-style:italic",del:"text-decoration:line-through",ul:"margin:.5em 0;padding-left:2em",ol:"margin:.5em 0;padding-left:2em",li:"margin:.25em 0","task-item":"list-style:none","task-checkbox":"margin-right:.5em"};function o(o,a={}){if(!o||"string"!=typeof o)return"";const{fence_plugin:l,inline_styles:i=!1,bidirectional:s=!1,lazy_linefeeds:d=!1}=a,u=function(t,n){return function(r,o=""){if(t){let e=n[r];return e||o?(o&&o.includes("text-align")&&e&&e.includes("text-align")&&(e=e.replace(/text-align:[^;]+;?/,"").trim(),e&&!e.endsWith(";")&&(e+=";")),` style="${o?e?`${e}${o}`:o:e}"`):""}{const t=` class="${e}${r}"`;return o?`${t} style="${o}"`:t}}}(i,r);function $(e){return e.replace(/[&<>"']/g,e=>n[e])}const f=s?e=>` data-qd="${$(e)}"`:()=>"";function g(e,t=!1){if(!e)return"";if(t)return e;const n=e.trim(),r=n.toLowerCase(),o=["javascript:","vbscript:","data:"];for(const e of o)if(r.startsWith(e))return"data:"===e&&r.startsWith("data:image/")?n:"#";return n}let p=o;const h=[],m=[];p=p.replace(/^(```|~~~)([^\n]*)\n([\s\S]*?)^\1$/gm,(e,n,r,o)=>{const a=`${t}${h.length}§`,c=r?r.trim():"";return l&&l.render&&"function"==typeof l.render?h.push({lang:c,code:o.trimEnd(),custom:!0,fence:n,hasReverse:!!l.reverse}):h.push({lang:c,code:$(o.trimEnd()),custom:!1,fence:n}),a}),p=p.replace(/`([^`]+)`/g,(e,t)=>{const n=`§IC${m.length}§`;return m.push($(t)),n}),p=$(p),p=function(e,t){const n=e.split("\n"),r=[];let o=!1,a=[];for(let e=0;e<n.length;e++){const l=n[e].trim();if(l.includes("|")&&(l.startsWith("|")||/[^\\|]/.test(l)))o||(o=!0,a=[]),a.push(l);else{if(o){const e=c(a,t);e?r.push(e):r.push(...a),o=!1,a=[]}r.push(n[e])}}if(o&&a.length>0){const e=c(a,t);e?r.push(e):r.push(...a)}return r.join("\n")}(p,u),p=p.replace(/^(#{1,6})\s+(.+?)\s*#*$/gm,(e,t,n)=>{const r=t.length;return`<h${r}${u("h"+r)}${f(t)}>${n}</h${r}>`}),p=p.replace(/^&gt;\s+(.+)$/gm,`<blockquote${u("blockquote")}>$1</blockquote>`),p=p.replace(/<\/blockquote>\n<blockquote>/g,"\n"),p=p.replace(/^---+\s*$/gm,`<hr${u("hr")}>`),p=function(t,n,r,o){const a=t.split("\n"),c=[],l=[],i=e=>e.replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[e])),s=o?e=>` data-qd="${i(e)}"`:()=>"";for(let t=0;t<a.length;t++){const o=a[t],i=o.match(/^(\s*)([*\-+]|\d+\.)\s+(.+)$/);if(i){const[,t,o,a]=i,d=Math.floor(t.length/2),u=/^\d+\./.test(o),$=u?"ol":"ul";let f=a,g="";const p=a.match(/^\[([x ])\]\s+(.*)$/i);if(p&&!u){const[,t,n]=p,o="x"===t.toLowerCase();f=`<input type="checkbox"${r?' style="margin-right:.5em"':` class="${e}task-checkbox"`}${o?" checked":""} disabled> ${n}`,g=r?' style="list-style:none"':` class="${e}task-item"`}for(;l.length>d+1;){const e=l.pop();c.push(`</${e.type}>`)}if(l.length===d)l.push({type:$,level:d}),c.push(`<${$}${n($)}>`);else if(l.length===d+1){const e=l[l.length-1];e.type!==$&&(c.push(`</${e.type}>`),l.pop(),l.push({type:$,level:d}),c.push(`<${$}${n($)}>`))}const h=g||n("li");c.push(`<li${h}${s(o)}>${f}</li>`)}else{for(;l.length>0;){const e=l.pop();c.push(`</${e.type}>`)}c.push(o)}}for(;l.length>0;){const e=l.pop();c.push(`</${e.type}>`)}return c.join("\n")}(p,u,i,s),p=p.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(e,t,n)=>{const r=g(n,a.allow_unsafe_urls),o=s&&t?` data-qd-alt="${$(t)}"`:"",c=s?` data-qd-src="${$(n)}"`:"";return`<img${u("img")} src="${r}" alt="${t}"${o}${c}${f("!")}>`}),p=p.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>{const r=g(n,a.allow_unsafe_urls),o=/^https?:\/\//i.test(r)?' rel="noopener noreferrer"':"",c=s?` data-qd-text="${$(t)}"`:"";return`<a${u("a")} href="${r}"${o}${c}${f("[")}>${t}</a>`}),p=p.replace(/(^|\s)(https?:\/\/[^\s<]+)/g,(e,t,n)=>{const r=g(n,a.allow_unsafe_urls);return`${t}<a${u("a")} href="${r}" rel="noopener noreferrer">${n}</a>`});if([[/\*\*(.+?)\*\*/g,"strong","**"],[/__(.+?)__/g,"strong","__"],[/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g,"em","*"],[/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g,"em","_"],[/~~(.+?)~~/g,"del","~~"]].forEach(([e,t,n])=>{p=p.replace(e,`<${t}${u(t)}${f(n)}>$1</${t}>`)}),d){const e=[];let t=0;p=p.replace(/<(table|[uo]l)[^>]*>[\s\S]*?<\/\1>/g,n=>(e[t]=n,`§B${t++}§`)),p=p.replace(/\n\n+/g,"§P§").replace(/(<\/(?:h[1-6]|blockquote|pre)>)\n/g,"$1§N§").replace(/(<(?:h[1-6]|blockquote|pre|hr)[^>]*>)\n/g,"$1§N§").replace(/\n(<(?:h[1-6]|blockquote|pre|hr)[^>]*>)/g,"§N§$1").replace(/\n(§B\d+§)/g,"§N§$1").replace(/(§B\d+§)\n/g,"$1§N§").replace(/\n/g,`<br${u("br")}>`).replace(/§N§/g,"\n").replace(/§P§/g,"</p><p>"),e.forEach((e,t)=>p=p.replace(`§B${t}§`,e)),p="<p>"+p+"</p>"}else p=p.replace(/ {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="${$(e.lang)}"`:"",a=s?` data-qd-fence="${$(e.fence)}"`:"";r=`<pre${u("pre")}${a}${o}><code${n}>${$(e.code)}</code></pre>`}else s&&(r=r.replace(/^<(\w+)/,`<$1 data-qd-fence="${$(e.fence)}" data-qd-lang="${$(e.lang)}" data-qd-source="${$(e.code)}"`));else{const t=!i&&e.lang?` class="language-${e.lang}"`:"",n=i?u("code"):t,o=s&&e.lang?` data-qd-lang="${$(e.lang)}"`:"",a=s?` data-qd-fence="${$(e.fence)}"`:"";r=`<pre${u("pre")}${a}${o}><code${n}>${e.code}</code></pre>`}const o=`${t}${n}§`;p=p.replace(o,r)}),m.forEach((e,t)=>{const n=`§IC${t}§`;p=p.replace(n,`<code${u("code")}${f("`")}>${e}</code>`)}),p.trim()}function a(e,t){return[[/\*\*(.+?)\*\*/g,"strong"],[/__(.+?)__/g,"strong"],[/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g,"em"],[/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g,"em"],[/~~(.+?)~~/g,"del"],[/`([^`]+)`/g,"code"]].forEach(([n,r])=>{e=e.replace(n,`<${r}${t(r)}>$1</${r}>`)}),e}function c(e,t){if(e.length<2)return null;let n=-1;for(let t=1;t<e.length;t++)if(/^\|?[\s\-:|]+\|?$/.test(e[t])&&e[t].includes("-")){n=t;break}if(-1===n)return null;const r=e.slice(0,n),o=e.slice(n+1),c=e[n].trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(e=>{const t=e.trim();return t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left"});let l=`<table${t("table")}>\n`;return l+=`<thead${t("thead")}>\n`,r.forEach(e=>{l+=`<tr${t("tr")}>\n`;e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").forEach((e,n)=>{const r=c[n]&&"left"!==c[n]?`text-align:${c[n]}`:"",o=a(e.trim(),t);l+=`<th${t("th",r)}>${o}</th>\n`}),l+="</tr>\n"}),l+="</thead>\n",o.length>0&&(l+=`<tbody${t("tbody")}>\n`,o.forEach(e=>{l+=`<tr${t("tr")}>\n`;e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").forEach((e,n)=>{const r=c[n]&&"left"!==c[n]?`text-align:${c[n]}`:"",o=a(e.trim(),t);l+=`<td${t("td",r)}>${o}</td>\n`}),l+="</tr>\n"}),l+="</tbody>\n"),l+="</table>",l}function l(e,t={}){return o(e,{...t,bidirectional:!0})}o.emitStyles=function(e="quikdown-",t="light"){const n=r,o={"#f4f4f4":"#2a2a2a","#f0f0f0":"#2a2a2a","#f2f2f2":"#2a2a2a","#ddd":"#3a3a3a","#06c":"#6db3f2",_textColor:"#e0e0e0"},a={_textColor:"#333"};let c="";for(const[r,l]of Object.entries(n)){let n=l;if("dark"===t&&o){for(const[e,t]of Object.entries(o))e.startsWith("_")||(n=n.replace(new RegExp(e,"g"),t));["h1","h2","h3","h4","h5","h6","td","li","blockquote"].includes(r)&&(n+=`;color:${o._textColor}`)}else if("light"===t&&a){["h1","h2","h3","h4","h5","h6","td","li","blockquote"].includes(r)&&(n+=`;color:${a._textColor}`)}c+=`.${e}${r} { ${n} }\n`}return c},o.configure=function(e){return function(t){return o(t,e)}},o.version="1.2.2","undefined"!=typeof module&&module.exports&&(module.exports=o),"undefined"!=typeof window&&(window.quikdown=o),Object.keys(o).forEach(e=>{l[e]=o[e]}),l.toMarkdown=function(e,t={}){let n;if("string"==typeof e)n=document.createElement("div"),n.innerHTML=e;else{if(!(e instanceof Element))return"";n=e}function r(e,n={}){if(e.nodeType===Node.TEXT_NODE)return e.textContent;if(e.nodeType!==Node.ELEMENT_NODE)return"";const a=e.tagName.toLowerCase(),c=e.getAttribute("data-qd");let l="";for(const t of e.childNodes)l+=r(t,{parentTag:a,...n});switch(a){case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":const n=parseInt(a[1]);return`${c||"#".repeat(n)} ${l.trim()}\n\n`;case"strong":case"b":if(!l)return"";const r=c||"**";return`${r}${l}${r}`;case"em":case"i":if(!l)return"";const i=c||"*";return`${i}${l}${i}`;case"del":case"s":case"strike":if(!l)return"";const s=c||"~~";return`${s}${l}${s}`;case"code":if(!l)return"";const d=c||"`";return`${d}${l}${d}`;case"pre":const u=e.getAttribute("data-qd-fence")||c||"```",$=e.getAttribute("data-qd-lang")||"";if(t.fence_plugin&&t.fence_plugin.reverse&&$)try{const n=t.fence_plugin.reverse(e);if(n&&n.content){const e=n.fence||u;return`${e}${n.lang||$}\n${n.content}\n${e}\n\n`}}catch(e){console.warn("Fence reverse handler error:",e)}const f=e.getAttribute("data-qd-source");if(f)return`${u}${$}\n${f}\n${u}\n\n`;const g=e.querySelector("code");return`${u}${$}\n${(g?g.textContent:l).trimEnd()}\n${u}\n\n`;case"blockquote":const p=c||">";return l.trim().split("\n").map(e=>`${p} ${e}`).join("\n")+"\n\n";case"hr":return`${c||"---"}\n\n`;case"br":return`${c||" "}\n`;case"a":const h=e.getAttribute("data-qd-text")||l.trim(),m=e.getAttribute("href")||"";return h!==m||c?`[${h}](${m})`:`<${m}>`;case"img":return`${c||"!"}[${e.getAttribute("data-qd-alt")||e.getAttribute("alt")||""}](${e.getAttribute("data-qd-src")||e.getAttribute("src")||""})`;case"ul":case"ol":return o(e,"ol"===a)+"\n";case"li":case"span":default:return l;case"table":return function(e){let t="";const n=e.getAttribute("data-qd-align"),r=n?n.split(","):[],o=e.querySelector("thead");if(o){const e=o.querySelector("tr");if(e){const n=[];for(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 a=e.querySelector("tbody");if(a)for(const e of a.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 a=e.querySelector(".mermaid-source");if(a){const e=document.createElement("div");e.innerHTML=a.innerHTML;return`${t}${n}\n${e.textContent}\n${t}\n\n`}const c=e.querySelector(".mermaid");if(c&&c.textContent.includes("graph"))return`${t}${n}\n${c.textContent.trim()}\n${t}\n\n`}if(e.classList&&e.classList.contains("mermaid")){const t=e.getAttribute("data-qd-fence")||"```";return`${t}${e.getAttribute("data-qd-lang")||"mermaid"}\n${e.textContent.trim()}\n${t}\n\n`}return l}}function o(e,t,n=0){let a="",c=1;const l=" ".repeat(n);for(const i of e.children){if("LI"!==i.tagName)continue;let e=i.getAttribute("data-qd")||(t?`${c}.`:"-");const s=i.querySelector('input[type="checkbox"]');if(s){const t=s.checked?"x":" ";e="-";let n="";for(const e of i.childNodes)e.nodeType===Node.TEXT_NODE?n+=e.textContent:e.tagName&&"INPUT"!==e.tagName&&(n+=r(e));a+=`${l}${e} [${t}] ${n.trim()}\n`}else{let t="";for(const e of i.childNodes)"UL"===e.tagName||"OL"===e.tagName?t+=o(e,"OL"===e.tagName,n+1):t+=r(e);a+=`${l}${e} ${t.trim()}\n`}c++}return a}let a=r(n);return a=a.replace(/\n{3,}/g,"\n\n"),a=a.trim(),a},l.configure=function(e){return function(t){return l(t,e)}},"undefined"!=typeof module&&module.exports&&(module.exports=l),"undefined"!=typeof window&&(window.quikdown_bd=l);export{l as default};
7
+ const e="quikdown-",t="§CB",n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},r={h1:"font-size:2em;font-weight:600;margin:.67em 0;text-align:left",h2:"font-size:1.5em;font-weight:600;margin:.83em 0",h3:"font-size:1.25em;font-weight:600;margin:1em 0",h4:"font-size:1em;font-weight:600;margin:1.33em 0",h5:"font-size:.875em;font-weight:600;margin:1.67em 0",h6:"font-size:.85em;font-weight:600;margin:2em 0",pre:"background:#f4f4f4;padding:10px;border-radius:4px;overflow-x:auto;margin:1em 0",code:"background:#f0f0f0;padding:2px 4px;border-radius:3px;font-family:monospace",blockquote:"border-left:4px solid #ddd;margin-left:0;padding-left:1em",table:"border-collapse:collapse;width:100%;margin:1em 0",th:"border:1px solid #ddd;padding:8px;background-color:#f2f2f2;font-weight:bold;text-align:left",td:"border:1px solid #ddd;padding:8px;text-align:left",hr:"border:none;border-top:1px solid #ddd;margin:1em 0",img:"max-width:100%;height:auto",a:"color:#06c;text-decoration:underline",strong:"font-weight:bold",em:"font-style:italic",del:"text-decoration:line-through",ul:"margin:.5em 0;padding-left:2em",ol:"margin:.5em 0;padding-left:2em",li:"margin:.25em 0","task-item":"list-style:none","task-checkbox":"margin-right:.5em"};function o(o,a={}){if(!o||"string"!=typeof o)return"";const{fence_plugin:l,inline_styles:i=!1,bidirectional:s=!1,lazy_linefeeds:d=!1,allow_unsafe_html:u=!1}=a,$=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 g=s?e=>` data-qd="${f(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 a=`${t}${m.length}§`,c=r?r.trim():"";return l&&l.render&&"function"==typeof l.render?m.push({lang:c,code:o.trimEnd(),custom:!0,fence:n,hasReverse:!!l.reverse}):m.push({lang:c,code:f(o.trimEnd()),custom:!1,fence:n}),a}),h=h.replace(/`([^`]+)`/g,(e,t)=>{const n=`§IC${b.length}§`;return b.push(f(t)),n}),u||(h=f(h)),h=function(e,t){const n=e.split("\n"),r=[];let o=!1,a=[];for(let e=0;e<n.length;e++){const l=n[e].trim();if(l.includes("|")&&(l.startsWith("|")||/[^\\|]/.test(l)))o||(o=!0,a=[]),a.push(l);else{if(o){const e=c(a,t);e?r.push(e):r.push(...a),o=!1,a=[]}r.push(n[e])}}if(o&&a.length>0){const e=c(a,t);e?r.push(e):r.push(...a)}return r.join("\n")}(h,$),h=h.replace(/^(#{1,6})\s+(.+?)\s*#*$/gm,(e,t,n)=>{const r=t.length;return`<h${r}${$("h"+r)}${g(t)}>${n}</h${r}>`}),h=h.replace(/^&gt;\s+(.+)$/gm,`<blockquote${$("blockquote")}>$1</blockquote>`),h=h.replace(/<\/blockquote>\n<blockquote>/g,"\n"),h=h.replace(/^---+\s*$/gm,`<hr${$("hr")}>`),h=function(t,n,r,o){const a=t.split("\n"),c=[],l=[],i=e=>e.replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[e])),s=o?e=>` data-qd="${i(e)}"`:()=>"";for(let t=0;t<a.length;t++){const o=a[t],i=o.match(/^(\s*)([*\-+]|\d+\.)\s+(.+)$/);if(i){const[,t,o,a]=i,d=Math.floor(t.length/2),u=/^\d+\./.test(o),$=u?"ol":"ul";let f=a,g="";const p=a.match(/^\[([x ])\]\s+(.*)$/i);if(p&&!u){const[,t,n]=p,o="x"===t.toLowerCase();f=`<input type="checkbox"${r?' style="margin-right:.5em"':` class="${e}task-checkbox"`}${o?" checked":""} disabled> ${n}`,g=r?' style="list-style:none"':` class="${e}task-item"`}for(;l.length>d+1;){const e=l.pop();c.push(`</${e.type}>`)}if(l.length===d)l.push({type:$,level:d}),c.push(`<${$}${n($)}>`);else if(l.length===d+1){const e=l[l.length-1];e.type!==$&&(c.push(`</${e.type}>`),l.pop(),l.push({type:$,level:d}),c.push(`<${$}${n($)}>`))}const h=g||n("li");c.push(`<li${h}${s(o)}>${f}</li>`)}else{for(;l.length>0;){const e=l.pop();c.push(`</${e.type}>`)}c.push(o)}}for(;l.length>0;){const e=l.pop();c.push(`</${e.type}>`)}return c.join("\n")}(h,$,i,s),h=h.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(e,t,n)=>{const r=p(n,a.allow_unsafe_urls),o=s&&t?` data-qd-alt="${f(t)}"`:"",c=s?` data-qd-src="${f(n)}"`:"";return`<img${$("img")} src="${r}" alt="${t}"${o}${c}${g("!")}>`}),h=h.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>{const r=p(n,a.allow_unsafe_urls),o=/^https?:\/\//i.test(r)?' rel="noopener noreferrer"':"",c=s?` data-qd-text="${f(t)}"`:"";return`<a${$("a")} href="${r}"${o}${c}${g("[")}>${t}</a>`}),h=h.replace(/(^|\s)(https?:\/\/[^\s<]+)/g,(e,t,n)=>{const r=p(n,a.allow_unsafe_urls);return`${t}<a${$("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}${$(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${$("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${$("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?$("code"):t,o=s&&e.lang?` data-qd-lang="${f(e.lang)}"`:"",a=s?` data-qd-fence="${f(e.fence)}"`:"";r=`<pre${$("pre")}${a}${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?$("code"):t,o=s&&e.lang?` data-qd-lang="${f(e.lang)}"`:"",a=s?` data-qd-fence="${f(e.fence)}"`:"";r=`<pre${$("pre")}${a}${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${$("code")}${g("`")}>${e}</code>`)}),h.trim()}function a(e,t){return[[/\*\*(.+?)\*\*/g,"strong"],[/__(.+?)__/g,"strong"],[/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g,"em"],[/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g,"em"],[/~~(.+?)~~/g,"del"],[/`([^`]+)`/g,"code"]].forEach(([n,r])=>{e=e.replace(n,`<${r}${t(r)}>$1</${r}>`)}),e}function c(e,t){if(e.length<2)return null;let n=-1;for(let t=1;t<e.length;t++)if(/^\|?[\s\-:|]+\|?$/.test(e[t])&&e[t].includes("-")){n=t;break}if(-1===n)return null;const r=e.slice(0,n),o=e.slice(n+1),c=e[n].trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(e=>{const t=e.trim();return t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left"});let l=`<table${t("table")}>\n`;return l+=`<thead${t("thead")}>\n`,r.forEach(e=>{l+=`<tr${t("tr")}>\n`;e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").forEach((e,n)=>{const r=c[n]&&"left"!==c[n]?`text-align:${c[n]}`:"",o=a(e.trim(),t);l+=`<th${t("th",r)}>${o}</th>\n`}),l+="</tr>\n"}),l+="</thead>\n",o.length>0&&(l+=`<tbody${t("tbody")}>\n`,o.forEach(e=>{l+=`<tr${t("tr")}>\n`;e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").forEach((e,n)=>{const r=c[n]&&"left"!==c[n]?`text-align:${c[n]}`:"",o=a(e.trim(),t);l+=`<td${t("td",r)}>${o}</td>\n`}),l+="</tr>\n"}),l+="</tbody>\n"),l+="</table>",l}function l(e,t={}){return o(e,{...t,bidirectional:!0})}o.emitStyles=function(e="quikdown-",t="light"){const n=r,o={"#f4f4f4":"#2a2a2a","#f0f0f0":"#2a2a2a","#f2f2f2":"#2a2a2a","#ddd":"#3a3a3a","#06c":"#6db3f2",_textColor:"#e0e0e0"},a={_textColor:"#333"};let c="";for(const[r,l]of Object.entries(n)){let n=l;if("dark"===t&&o){for(const[e,t]of Object.entries(o))e.startsWith("_")||(n=n.replace(new RegExp(e,"g"),t));["h1","h2","h3","h4","h5","h6","td","li","blockquote"].includes(r)&&(n+=`;color:${o._textColor}`)}else if("light"===t&&a){["h1","h2","h3","h4","h5","h6","td","li","blockquote"].includes(r)&&(n+=`;color:${a._textColor}`)}c+=`.${e}${r} { ${n} }\n`}return c},o.configure=function(e){return function(t){return o(t,e)}},o.version="1.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 a=e.tagName.toLowerCase(),c=e.getAttribute("data-qd");let l="";for(const t of e.childNodes)l+=r(t,{parentTag:a,...n});switch(a){case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":const n=parseInt(a[1]);return`${c||"#".repeat(n)} ${l.trim()}\n\n`;case"strong":case"b":if(!l)return"";const r=c||"**";return`${r}${l}${r}`;case"em":case"i":if(!l)return"";const i=c||"*";return`${i}${l}${i}`;case"del":case"s":case"strike":if(!l)return"";const s=c||"~~";return`${s}${l}${s}`;case"code":if(!l)return"";const d=c||"`";return`${d}${l}${d}`;case"pre":const u=e.getAttribute("data-qd-fence")||c||"```",$=e.getAttribute("data-qd-lang")||"";if(t.fence_plugin&&t.fence_plugin.reverse&&$)try{const n=t.fence_plugin.reverse(e);if(n&&n.content){const e=n.fence||u;return`${e}${n.lang||$}\n${n.content}\n${e}\n\n`}}catch(e){console.warn("Fence reverse handler error:",e)}const f=e.getAttribute("data-qd-source");if(f)return`${u}${$}\n${f}\n${u}\n\n`;const g=e.querySelector("code");return`${u}${$}\n${(g?g.textContent:l).trimEnd()}\n${u}\n\n`;case"blockquote":const p=c||">";return l.trim().split("\n").map(e=>`${p} ${e}`).join("\n")+"\n\n";case"hr":return`${c||"---"}\n\n`;case"br":return`${c||" "}\n`;case"a":const h=e.getAttribute("data-qd-text")||l.trim(),m=e.getAttribute("href")||"";return h!==m||c?`[${h}](${m})`:`<${m}>`;case"img":return`${c||"!"}[${e.getAttribute("data-qd-alt")||e.getAttribute("alt")||""}](${e.getAttribute("data-qd-src")||e.getAttribute("src")||""})`;case"ul":case"ol":return o(e,"ol"===a)+"\n";case"li":case"span":default:return l;case"table":return function(e){let t="";const n=e.getAttribute("data-qd-align"),r=n?n.split(","):[],o=e.querySelector("thead");if(o){const e=o.querySelector("tr");if(e){const n=[];for(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 a=e.querySelector("tbody");if(a)for(const e of a.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 a=e.querySelector(".mermaid-source");if(a){const e=document.createElement("div");e.innerHTML=a.innerHTML;return`${t}${n}\n${e.textContent}\n${t}\n\n`}const c=e.querySelector(".mermaid");if(c&&c.textContent.includes("graph"))return`${t}${n}\n${c.textContent.trim()}\n${t}\n\n`}if(e.classList&&e.classList.contains("mermaid")){const t=e.getAttribute("data-qd-fence")||"```";return`${t}${e.getAttribute("data-qd-lang")||"mermaid"}\n${e.textContent.trim()}\n${t}\n\n`}return l}}function o(e,t,n=0){let a="",c=1;const l=" ".repeat(n);for(const i of e.children){if("LI"!==i.tagName)continue;let e=i.getAttribute("data-qd")||(t?`${c}.`:"-");const s=i.querySelector('input[type="checkbox"]');if(s){const t=s.checked?"x":" ";e="-";let n="";for(const e of i.childNodes)e.nodeType===Node.TEXT_NODE?n+=e.textContent:e.tagName&&"INPUT"!==e.tagName&&(n+=r(e));a+=`${l}${e} [${t}] ${n.trim()}\n`}else{let t="";for(const e of i.childNodes)"UL"===e.tagName||"OL"===e.tagName?t+=o(e,"OL"===e.tagName,n+1):t+=r(e);a+=`${l}${e} ${t.trim()}\n`}c++}return a}let a=r(n);return a=a.replace(/\n{3,}/g,"\n\n"),a=a.trim(),a},l.configure=function(e){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);export{l as default};
8
8
  //# sourceMappingURL=quikdown_bd.esm.min.js.map
Binary file