quikdown 1.2.10 → 1.2.11
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 +2 -2
- package/dist/quikdown.cjs +96 -3
- package/dist/quikdown.d.ts +12 -0
- package/dist/quikdown.dark.css +1 -1
- package/dist/quikdown.esm.js +96 -3
- 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 +96 -3
- 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 +96 -3
- package/dist/quikdown_bd.esm.js +96 -3
- 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 +96 -3
- 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 +232 -6
- package/dist/quikdown_edit.esm.js +232 -6
- 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 +232 -6
- 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 +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* quikdown_ast_html - AST to HTML Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.11
|
|
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;){if(r.match(/^(.+?)(?: {2}|\\\n|\n)/)&&r.includes("\n")){const e=r.indexOf("\n"),t=r.slice(0,e),i=r.slice(e+1);if(t.endsWith(" ")||t.endsWith("\\")){const e=t.replace(/\\$/,"").replace(/ +$/,"");e&&n.push(...c(e)),n.push({type:"br"}),r=i;continue}}const e=r.match(/^!\[([^\]]*)\]\(\s*([^)\s]+)\s*\)/);if(e){n.push({type:"image",alt:e[1],url:e[2].trim()}),r=r.slice(e[0].length);continue}const t=r.match(/^\[([^\]]+)\]\(\s*([^)\s]+)\s*\)/);if(t){n.push({type:"link",url:t[2].trim(),children:c(t[1])}),r=r.slice(t[0].length);continue}const i=r.match(/^`([^`]+)`/);if(i){n.push({type:"code",value:i[1]}),r=r.slice(i[0].length);continue}const s=r.match(/^(\*\*|__)(.+?)\1/);if(s){n.push({type:"strong",children:c(s[2])}),r=r.slice(s[0].length);continue}const l=r.match(/^~~(.+?)~~/);if(l){n.push({type:"del",children:c(l[1])}),r=r.slice(l[0].length);continue}const o=r.match(/^(\*|_)(?!\1)(.+?)(?<!\1)\1(?!\1)/);if(o){n.push({type:"em",children:c(o[2])}),r=r.slice(o[0].length);continue}const a=r.match(/^(https?:\/\/[^\s<>[\]]+)/);if(a){n.push({type:"link",url:a[1],children:[{type:"text",value:a[1]}]}),r=r.slice(a[0].length);continue}const u=r.search(/[`*_~![\\n]|https?:\/\//);if(-1===u){n.push({type:"text",value:r});break}0===u?(n.push({type:"text",value:r[0]}),r=r.slice(1)):(n.push({type:"text",value:r.slice(0,u)}),r=r.slice(u))}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.10","undefined"!=typeof module&&module.exports&&(module.exports=e),"undefined"!=typeof window&&(window.quikdown_ast=e);const l="quikdown-",o={"&":"&","<":"<",">":">",'"':""","'":"'"},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.10","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;){if(r.match(/^(.+?)(?: {2}|\\\n|\n)/)&&r.includes("\n")){const e=r.indexOf("\n"),t=r.slice(0,e),i=r.slice(e+1);if(t.endsWith(" ")||t.endsWith("\\")){const e=t.replace(/\\$/,"").replace(/ +$/,"");e&&n.push(...c(e)),n.push({type:"br"}),r=i;continue}}const e=r.match(/^!\[([^\]]*)\]\(\s*([^)\s]+)\s*\)/);if(e){n.push({type:"image",alt:e[1],url:e[2].trim()}),r=r.slice(e[0].length);continue}const t=r.match(/^\[([^\]]+)\]\(\s*([^)\s]+)\s*\)/);if(t){n.push({type:"link",url:t[2].trim(),children:c(t[1])}),r=r.slice(t[0].length);continue}const i=r.match(/^`([^`]+)`/);if(i){n.push({type:"code",value:i[1]}),r=r.slice(i[0].length);continue}const s=r.match(/^(\*\*|__)(.+?)\1/);if(s){n.push({type:"strong",children:c(s[2])}),r=r.slice(s[0].length);continue}const l=r.match(/^~~(.+?)~~/);if(l){n.push({type:"del",children:c(l[1])}),r=r.slice(l[0].length);continue}const o=r.match(/^(\*|_)(?!\1)(.+?)(?<!\1)\1(?!\1)/);if(o){n.push({type:"em",children:c(o[2])}),r=r.slice(o[0].length);continue}const a=r.match(/^(https?:\/\/[^\s<>[\]]+)/);if(a){n.push({type:"link",url:a[1],children:[{type:"text",value:a[1]}]}),r=r.slice(a[0].length);continue}const u=r.search(/[`*_~![\\n]|https?:\/\//);if(-1===u){n.push({type:"text",value:r});break}0===u?(n.push({type:"text",value:r[0]}),r=r.slice(1)):(n.push({type:"text",value:r.slice(0,u)}),r=r.slice(u))}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.11","undefined"!=typeof module&&module.exports&&(module.exports=e),"undefined"!=typeof window&&(window.quikdown_ast=e);const l="quikdown-",o={"&":"&","<":"<",">":">",'"':""","'":"'"},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.11","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
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* quikdown_ast_html - AST to HTML Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.11
|
|
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.
|
|
22
|
+
const quikdownVersion$1 = '1.2.11';
|
|
23
23
|
|
|
24
24
|
// Safety limit to prevent infinite loops in list parsing
|
|
25
25
|
const MAX_LOOP_ITERATIONS = 1000;
|
|
@@ -512,7 +512,7 @@
|
|
|
512
512
|
|
|
513
513
|
|
|
514
514
|
// Version will be injected at build time
|
|
515
|
-
const quikdownVersion = '1.2.
|
|
515
|
+
const quikdownVersion = '1.2.11';
|
|
516
516
|
|
|
517
517
|
// Constants
|
|
518
518
|
const CLASS_PREFIX = 'quikdown-';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* quikdown_ast_html - AST to HTML Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.11
|
|
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;){if(i.match(/^(.+?)(?: {2}|\\\n|\n)/)&&i.includes("\n")){const e=i.indexOf("\n"),t=i.slice(0,e),r=i.slice(e+1);if(t.endsWith(" ")||t.endsWith("\\")){const e=t.replace(/\\$/,"").replace(/ +$/,"");e&&n.push(...c(e)),n.push({type:"br"}),i=r;continue}}const e=i.match(/^!\[([^\]]*)\]\(\s*([^)\s]+)\s*\)/);if(e){n.push({type:"image",alt:e[1],url:e[2].trim()}),i=i.slice(e[0].length);continue}const t=i.match(/^\[([^\]]+)\]\(\s*([^)\s]+)\s*\)/);if(t){n.push({type:"link",url:t[2].trim(),children:c(t[1])}),i=i.slice(t[0].length);continue}const r=i.match(/^`([^`]+)`/);if(r){n.push({type:"code",value:r[1]}),i=i.slice(r[0].length);continue}const s=i.match(/^(\*\*|__)(.+?)\1/);if(s){n.push({type:"strong",children:c(s[2])}),i=i.slice(s[0].length);continue}const l=i.match(/^~~(.+?)~~/);if(l){n.push({type:"del",children:c(l[1])}),i=i.slice(l[0].length);continue}const o=i.match(/^(\*|_)(?!\1)(.+?)(?<!\1)\1(?!\1)/);if(o){n.push({type:"em",children:c(o[2])}),i=i.slice(o[0].length);continue}const a=i.match(/^(https?:\/\/[^\s<>[\]]+)/);if(a){n.push({type:"link",url:a[1],children:[{type:"text",value:a[1]}]}),i=i.slice(a[0].length);continue}const u=i.search(/[`*_~![\\n]|https?:\/\//);if(-1===u){n.push({type:"text",value:i});break}0===u?(n.push({type:"text",value:i[0]}),i=i.slice(1)):(n.push({type:"text",value:i.slice(0,u)}),i=i.slice(u))}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.10","undefined"!=typeof module&&module.exports&&(module.exports=e),"undefined"!=typeof window&&(window.quikdown_ast=e);const l="quikdown-",o={"&":"&","<":"<",">":">",'"':""","'":"'"},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.10","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;){if(i.match(/^(.+?)(?: {2}|\\\n|\n)/)&&i.includes("\n")){const e=i.indexOf("\n"),t=i.slice(0,e),r=i.slice(e+1);if(t.endsWith(" ")||t.endsWith("\\")){const e=t.replace(/\\$/,"").replace(/ +$/,"");e&&n.push(...c(e)),n.push({type:"br"}),i=r;continue}}const e=i.match(/^!\[([^\]]*)\]\(\s*([^)\s]+)\s*\)/);if(e){n.push({type:"image",alt:e[1],url:e[2].trim()}),i=i.slice(e[0].length);continue}const t=i.match(/^\[([^\]]+)\]\(\s*([^)\s]+)\s*\)/);if(t){n.push({type:"link",url:t[2].trim(),children:c(t[1])}),i=i.slice(t[0].length);continue}const r=i.match(/^`([^`]+)`/);if(r){n.push({type:"code",value:r[1]}),i=i.slice(r[0].length);continue}const s=i.match(/^(\*\*|__)(.+?)\1/);if(s){n.push({type:"strong",children:c(s[2])}),i=i.slice(s[0].length);continue}const l=i.match(/^~~(.+?)~~/);if(l){n.push({type:"del",children:c(l[1])}),i=i.slice(l[0].length);continue}const o=i.match(/^(\*|_)(?!\1)(.+?)(?<!\1)\1(?!\1)/);if(o){n.push({type:"em",children:c(o[2])}),i=i.slice(o[0].length);continue}const a=i.match(/^(https?:\/\/[^\s<>[\]]+)/);if(a){n.push({type:"link",url:a[1],children:[{type:"text",value:a[1]}]}),i=i.slice(a[0].length);continue}const u=i.search(/[`*_~![\\n]|https?:\/\//);if(-1===u){n.push({type:"text",value:i});break}0===u?(n.push({type:"text",value:i[0]}),i=i.slice(1)):(n.push({type:"text",value:i.slice(0,u)}),i=i.slice(u))}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.11","undefined"!=typeof module&&module.exports&&(module.exports=e),"undefined"!=typeof window&&(window.quikdown_ast=e);const l="quikdown-",o={"&":"&","<":"<",">":">",'"':""","'":"'"},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.11","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
|
|
Binary file
|
package/dist/quikdown_bd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* quikdown_bd - Bidirectional Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.11
|
|
4
4
|
* @license BSD-2-Clause
|
|
5
5
|
* @copyright DeftIO 2025
|
|
6
6
|
*/
|
|
@@ -114,7 +114,7 @@ function isDashHRLine(trimmed) {
|
|
|
114
114
|
// ────────────────────────────────────────────────────────────────────
|
|
115
115
|
|
|
116
116
|
/** Build-time version stamp (injected by tools/updateVersion) */
|
|
117
|
-
const quikdownVersion = '1.2.
|
|
117
|
+
const quikdownVersion = '1.2.11';
|
|
118
118
|
|
|
119
119
|
/** CSS class prefix used for all generated elements */
|
|
120
120
|
const CLASS_PREFIX = 'quikdown-';
|
|
@@ -122,6 +122,10 @@ const CLASS_PREFIX = 'quikdown-';
|
|
|
122
122
|
/** Placeholder sigils — chosen to be extremely unlikely in real text */
|
|
123
123
|
const PLACEHOLDER_CB = '§CB'; // fenced code blocks
|
|
124
124
|
const PLACEHOLDER_IC = '§IC'; // inline code spans
|
|
125
|
+
const PLACEHOLDER_HT = '§HT'; // safe HTML tags (limited mode)
|
|
126
|
+
|
|
127
|
+
/** Attributes whose values need URL sanitization */
|
|
128
|
+
const URL_ATTRIBUTES = { href:1, src:1, action:1, formaction:1 };
|
|
125
129
|
|
|
126
130
|
/** HTML entity escape map */
|
|
127
131
|
const ESC_MAP = {'&':'&','<':'<','>':'>','"':'"',"'":'''};
|
|
@@ -256,6 +260,46 @@ function quikdown(markdown, options = {}) {
|
|
|
256
260
|
return trimmedUrl;
|
|
257
261
|
}
|
|
258
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Sanitize attributes on an HTML tag string for limited mode.
|
|
265
|
+
* Strips on* event handlers (case-insensitive) and runs sanitizeUrl()
|
|
266
|
+
* on href/src/action/formaction values.
|
|
267
|
+
*/
|
|
268
|
+
function sanitizeHtmlTagAttrs(tagStr) {
|
|
269
|
+
// Self-closing or void tag without attributes — pass through
|
|
270
|
+
if (!/\s/.test(tagStr.replace(/<\/?[a-zA-Z][a-zA-Z0-9]*/, '').replace(/\/?>$/, ''))) {
|
|
271
|
+
return tagStr;
|
|
272
|
+
}
|
|
273
|
+
// Parse: <tagname ...attrs... > or <tagname ...attrs... />
|
|
274
|
+
const m = tagStr.match(/^(<\/?[a-zA-Z][a-zA-Z0-9]*)([\s\S]*?)(\/?>)$/);
|
|
275
|
+
/* istanbul ignore next - defensive: Phase 1.5 regex guarantees valid tag shape */
|
|
276
|
+
if (!m) return tagStr;
|
|
277
|
+
|
|
278
|
+
const [, open, attrStr, close] = m;
|
|
279
|
+
// Match individual attributes: name="value", name='value', name=value, or bare name
|
|
280
|
+
// eslint-disable-next-line security/detect-unsafe-regex -- linear: no nested quantifiers
|
|
281
|
+
const attrRe = /([a-zA-Z_][\w\-.:]*)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+)))?/g;
|
|
282
|
+
const attrs = [];
|
|
283
|
+
let am;
|
|
284
|
+
while ((am = attrRe.exec(attrStr)) !== null) {
|
|
285
|
+
const name = am[1];
|
|
286
|
+
const value = am[2] !== undefined ? am[2] : am[3] !== undefined ? am[3] : am[4];
|
|
287
|
+
// Strip event handlers (on*)
|
|
288
|
+
if (/^on/i.test(name)) continue;
|
|
289
|
+
if (value === undefined) {
|
|
290
|
+
// Boolean attribute (e.g. disabled, checked)
|
|
291
|
+
attrs.push(name);
|
|
292
|
+
} else {
|
|
293
|
+
let sanitized = value;
|
|
294
|
+
if (name.toLowerCase() in URL_ATTRIBUTES) {
|
|
295
|
+
sanitized = sanitizeUrl(value);
|
|
296
|
+
}
|
|
297
|
+
attrs.push(`${name}="${sanitized}"`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return open + (attrs.length ? ' ' + attrs.join(' ') : '') + close;
|
|
301
|
+
}
|
|
302
|
+
|
|
259
303
|
// ────────────────────────────────────────────────────────────────
|
|
260
304
|
// Phase 1 — Code Extraction
|
|
261
305
|
// ────────────────────────────────────────────────────────────────
|
|
@@ -307,17 +351,57 @@ function quikdown(markdown, options = {}) {
|
|
|
307
351
|
return placeholder;
|
|
308
352
|
});
|
|
309
353
|
|
|
354
|
+
// ────────────────────────────────────────────────────────────────
|
|
355
|
+
// Phase 1.5 — Safe HTML Extraction (whitelist mode)
|
|
356
|
+
// ────────────────────────────────────────────────────────────────
|
|
357
|
+
// When allow_unsafe_html is an object or array, extract whitelisted
|
|
358
|
+
// HTML tags, sanitize their attributes, and replace with placeholders.
|
|
359
|
+
// Non-whitelisted tags stay in text so Phase 2 will escape them.
|
|
360
|
+
|
|
361
|
+
const safeTags = [];
|
|
362
|
+
// Normalize: array → object for O(1) lookup; object used as-is
|
|
363
|
+
const htmlAllow = Array.isArray(allow_unsafe_html)
|
|
364
|
+
? Object.fromEntries(allow_unsafe_html.map(t => [t, 1]))
|
|
365
|
+
: (allow_unsafe_html && typeof allow_unsafe_html === 'object') ? allow_unsafe_html : null;
|
|
366
|
+
|
|
367
|
+
if (htmlAllow) {
|
|
368
|
+
// Pass through HTML comments — browsers render them as nothing
|
|
369
|
+
html = html.replace(/<!--[\s\S]*?-->/g, (match) => {
|
|
370
|
+
const idx = safeTags.length;
|
|
371
|
+
safeTags.push(match);
|
|
372
|
+
return `${PLACEHOLDER_HT}${idx}§`;
|
|
373
|
+
});
|
|
374
|
+
html = html.replace(/<\/?([a-zA-Z][a-zA-Z0-9]*)\b[^>]*\/?>/g, (match, tagName) => {
|
|
375
|
+
if (tagName.toLowerCase() in htmlAllow) {
|
|
376
|
+
const sanitized = sanitizeHtmlTagAttrs(match);
|
|
377
|
+
const idx = safeTags.length;
|
|
378
|
+
safeTags.push(sanitized);
|
|
379
|
+
return `${PLACEHOLDER_HT}${idx}§`;
|
|
380
|
+
}
|
|
381
|
+
// Not whitelisted — leave in text for Phase 2 to escape
|
|
382
|
+
return match;
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
310
386
|
// ────────────────────────────────────────────────────────────────
|
|
311
387
|
// Phase 2 — HTML Escaping
|
|
312
388
|
// ────────────────────────────────────────────────────────────────
|
|
313
389
|
// All remaining text (everything except code placeholders) is escaped
|
|
314
390
|
// to prevent XSS. The `allow_unsafe_html` option skips this for
|
|
315
391
|
// trusted pipelines that intentionally embed raw HTML.
|
|
392
|
+
// For whitelist mode, escaping still runs (only `true` bypasses it).
|
|
316
393
|
|
|
317
|
-
if (
|
|
394
|
+
if (allow_unsafe_html !== true) {
|
|
318
395
|
html = escapeHtml(html);
|
|
319
396
|
}
|
|
320
397
|
|
|
398
|
+
// Restore safe HTML tag placeholders after escaping
|
|
399
|
+
if (htmlAllow) {
|
|
400
|
+
safeTags.forEach((tag, i) => {
|
|
401
|
+
html = html.replace(`${PLACEHOLDER_HT}${i}§`, tag);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
321
405
|
// ────────────────────────────────────────────────────────────────
|
|
322
406
|
// Phase 3 — Block Scanning + Inline Formatting + Paragraphs
|
|
323
407
|
// ────────────────────────────────────────────────────────────────
|
|
@@ -559,6 +643,14 @@ function scanLineBlocks(text, getAttr, dataQd) {
|
|
|
559
643
|
while (i < lines.length) {
|
|
560
644
|
const line = lines[i];
|
|
561
645
|
|
|
646
|
+
// ── Markdown comment (reference-link hack) ──
|
|
647
|
+
// [//]: # (comment) or [//]: # "comment" or [//]: #
|
|
648
|
+
// These produce no output — standard markdown comment convention.
|
|
649
|
+
if (/^\[\/\/\]: #/.test(line)) {
|
|
650
|
+
i++;
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
|
|
562
654
|
// ── Heading ──
|
|
563
655
|
// Count leading '#' characters. Valid heading: 1-6 hashes then a space.
|
|
564
656
|
// Example: "## Hello World ##" → <h2>Hello World</h2>
|
|
@@ -923,6 +1015,7 @@ quikdown.configure = function(options) {
|
|
|
923
1015
|
/** Semantic version (injected at build time) */
|
|
924
1016
|
quikdown.version = quikdownVersion;
|
|
925
1017
|
|
|
1018
|
+
|
|
926
1019
|
// ════════════════════════════════════════════════════════════════════
|
|
927
1020
|
// Exports
|
|
928
1021
|
// ════════════════════════════════════════════════════════════════════
|
package/dist/quikdown_bd.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* quikdown_bd - Bidirectional Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.11
|
|
4
4
|
* @license BSD-2-Clause
|
|
5
5
|
* @copyright DeftIO 2025
|
|
6
6
|
*/
|
|
@@ -112,7 +112,7 @@ function isDashHRLine(trimmed) {
|
|
|
112
112
|
// ────────────────────────────────────────────────────────────────────
|
|
113
113
|
|
|
114
114
|
/** Build-time version stamp (injected by tools/updateVersion) */
|
|
115
|
-
const quikdownVersion = '1.2.
|
|
115
|
+
const quikdownVersion = '1.2.11';
|
|
116
116
|
|
|
117
117
|
/** CSS class prefix used for all generated elements */
|
|
118
118
|
const CLASS_PREFIX = 'quikdown-';
|
|
@@ -120,6 +120,10 @@ const CLASS_PREFIX = 'quikdown-';
|
|
|
120
120
|
/** Placeholder sigils — chosen to be extremely unlikely in real text */
|
|
121
121
|
const PLACEHOLDER_CB = '§CB'; // fenced code blocks
|
|
122
122
|
const PLACEHOLDER_IC = '§IC'; // inline code spans
|
|
123
|
+
const PLACEHOLDER_HT = '§HT'; // safe HTML tags (limited mode)
|
|
124
|
+
|
|
125
|
+
/** Attributes whose values need URL sanitization */
|
|
126
|
+
const URL_ATTRIBUTES = { href:1, src:1, action:1, formaction:1 };
|
|
123
127
|
|
|
124
128
|
/** HTML entity escape map */
|
|
125
129
|
const ESC_MAP = {'&':'&','<':'<','>':'>','"':'"',"'":'''};
|
|
@@ -254,6 +258,46 @@ function quikdown(markdown, options = {}) {
|
|
|
254
258
|
return trimmedUrl;
|
|
255
259
|
}
|
|
256
260
|
|
|
261
|
+
/**
|
|
262
|
+
* Sanitize attributes on an HTML tag string for limited mode.
|
|
263
|
+
* Strips on* event handlers (case-insensitive) and runs sanitizeUrl()
|
|
264
|
+
* on href/src/action/formaction values.
|
|
265
|
+
*/
|
|
266
|
+
function sanitizeHtmlTagAttrs(tagStr) {
|
|
267
|
+
// Self-closing or void tag without attributes — pass through
|
|
268
|
+
if (!/\s/.test(tagStr.replace(/<\/?[a-zA-Z][a-zA-Z0-9]*/, '').replace(/\/?>$/, ''))) {
|
|
269
|
+
return tagStr;
|
|
270
|
+
}
|
|
271
|
+
// Parse: <tagname ...attrs... > or <tagname ...attrs... />
|
|
272
|
+
const m = tagStr.match(/^(<\/?[a-zA-Z][a-zA-Z0-9]*)([\s\S]*?)(\/?>)$/);
|
|
273
|
+
/* istanbul ignore next - defensive: Phase 1.5 regex guarantees valid tag shape */
|
|
274
|
+
if (!m) return tagStr;
|
|
275
|
+
|
|
276
|
+
const [, open, attrStr, close] = m;
|
|
277
|
+
// Match individual attributes: name="value", name='value', name=value, or bare name
|
|
278
|
+
// eslint-disable-next-line security/detect-unsafe-regex -- linear: no nested quantifiers
|
|
279
|
+
const attrRe = /([a-zA-Z_][\w\-.:]*)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+)))?/g;
|
|
280
|
+
const attrs = [];
|
|
281
|
+
let am;
|
|
282
|
+
while ((am = attrRe.exec(attrStr)) !== null) {
|
|
283
|
+
const name = am[1];
|
|
284
|
+
const value = am[2] !== undefined ? am[2] : am[3] !== undefined ? am[3] : am[4];
|
|
285
|
+
// Strip event handlers (on*)
|
|
286
|
+
if (/^on/i.test(name)) continue;
|
|
287
|
+
if (value === undefined) {
|
|
288
|
+
// Boolean attribute (e.g. disabled, checked)
|
|
289
|
+
attrs.push(name);
|
|
290
|
+
} else {
|
|
291
|
+
let sanitized = value;
|
|
292
|
+
if (name.toLowerCase() in URL_ATTRIBUTES) {
|
|
293
|
+
sanitized = sanitizeUrl(value);
|
|
294
|
+
}
|
|
295
|
+
attrs.push(`${name}="${sanitized}"`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return open + (attrs.length ? ' ' + attrs.join(' ') : '') + close;
|
|
299
|
+
}
|
|
300
|
+
|
|
257
301
|
// ────────────────────────────────────────────────────────────────
|
|
258
302
|
// Phase 1 — Code Extraction
|
|
259
303
|
// ────────────────────────────────────────────────────────────────
|
|
@@ -305,17 +349,57 @@ function quikdown(markdown, options = {}) {
|
|
|
305
349
|
return placeholder;
|
|
306
350
|
});
|
|
307
351
|
|
|
352
|
+
// ────────────────────────────────────────────────────────────────
|
|
353
|
+
// Phase 1.5 — Safe HTML Extraction (whitelist mode)
|
|
354
|
+
// ────────────────────────────────────────────────────────────────
|
|
355
|
+
// When allow_unsafe_html is an object or array, extract whitelisted
|
|
356
|
+
// HTML tags, sanitize their attributes, and replace with placeholders.
|
|
357
|
+
// Non-whitelisted tags stay in text so Phase 2 will escape them.
|
|
358
|
+
|
|
359
|
+
const safeTags = [];
|
|
360
|
+
// Normalize: array → object for O(1) lookup; object used as-is
|
|
361
|
+
const htmlAllow = Array.isArray(allow_unsafe_html)
|
|
362
|
+
? Object.fromEntries(allow_unsafe_html.map(t => [t, 1]))
|
|
363
|
+
: (allow_unsafe_html && typeof allow_unsafe_html === 'object') ? allow_unsafe_html : null;
|
|
364
|
+
|
|
365
|
+
if (htmlAllow) {
|
|
366
|
+
// Pass through HTML comments — browsers render them as nothing
|
|
367
|
+
html = html.replace(/<!--[\s\S]*?-->/g, (match) => {
|
|
368
|
+
const idx = safeTags.length;
|
|
369
|
+
safeTags.push(match);
|
|
370
|
+
return `${PLACEHOLDER_HT}${idx}§`;
|
|
371
|
+
});
|
|
372
|
+
html = html.replace(/<\/?([a-zA-Z][a-zA-Z0-9]*)\b[^>]*\/?>/g, (match, tagName) => {
|
|
373
|
+
if (tagName.toLowerCase() in htmlAllow) {
|
|
374
|
+
const sanitized = sanitizeHtmlTagAttrs(match);
|
|
375
|
+
const idx = safeTags.length;
|
|
376
|
+
safeTags.push(sanitized);
|
|
377
|
+
return `${PLACEHOLDER_HT}${idx}§`;
|
|
378
|
+
}
|
|
379
|
+
// Not whitelisted — leave in text for Phase 2 to escape
|
|
380
|
+
return match;
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
308
384
|
// ────────────────────────────────────────────────────────────────
|
|
309
385
|
// Phase 2 — HTML Escaping
|
|
310
386
|
// ────────────────────────────────────────────────────────────────
|
|
311
387
|
// All remaining text (everything except code placeholders) is escaped
|
|
312
388
|
// to prevent XSS. The `allow_unsafe_html` option skips this for
|
|
313
389
|
// trusted pipelines that intentionally embed raw HTML.
|
|
390
|
+
// For whitelist mode, escaping still runs (only `true` bypasses it).
|
|
314
391
|
|
|
315
|
-
if (
|
|
392
|
+
if (allow_unsafe_html !== true) {
|
|
316
393
|
html = escapeHtml(html);
|
|
317
394
|
}
|
|
318
395
|
|
|
396
|
+
// Restore safe HTML tag placeholders after escaping
|
|
397
|
+
if (htmlAllow) {
|
|
398
|
+
safeTags.forEach((tag, i) => {
|
|
399
|
+
html = html.replace(`${PLACEHOLDER_HT}${i}§`, tag);
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
319
403
|
// ────────────────────────────────────────────────────────────────
|
|
320
404
|
// Phase 3 — Block Scanning + Inline Formatting + Paragraphs
|
|
321
405
|
// ────────────────────────────────────────────────────────────────
|
|
@@ -557,6 +641,14 @@ function scanLineBlocks(text, getAttr, dataQd) {
|
|
|
557
641
|
while (i < lines.length) {
|
|
558
642
|
const line = lines[i];
|
|
559
643
|
|
|
644
|
+
// ── Markdown comment (reference-link hack) ──
|
|
645
|
+
// [//]: # (comment) or [//]: # "comment" or [//]: #
|
|
646
|
+
// These produce no output — standard markdown comment convention.
|
|
647
|
+
if (/^\[\/\/\]: #/.test(line)) {
|
|
648
|
+
i++;
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
|
|
560
652
|
// ── Heading ──
|
|
561
653
|
// Count leading '#' characters. Valid heading: 1-6 hashes then a space.
|
|
562
654
|
// Example: "## Hello World ##" → <h2>Hello World</h2>
|
|
@@ -921,6 +1013,7 @@ quikdown.configure = function(options) {
|
|
|
921
1013
|
/** Semantic version (injected at build time) */
|
|
922
1014
|
quikdown.version = quikdownVersion;
|
|
923
1015
|
|
|
1016
|
+
|
|
924
1017
|
// ════════════════════════════════════════════════════════════════════
|
|
925
1018
|
// Exports
|
|
926
1019
|
// ════════════════════════════════════════════════════════════════════
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* quikdown_bd - Bidirectional Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.11
|
|
4
4
|
* @license BSD-2-Clause
|
|
5
5
|
* @copyright DeftIO 2025
|
|
6
6
|
*/
|
|
7
|
-
function e(e){if(e.length<3)return!1;for(let t=0;t<e.length;t++){const n=e[t];if("-"!==n){if(" "===n||"\t"===n){for(let n=t+1;n<e.length;n++)if(" "!==e[n]&&"\t"!==e[n])return!1;return t>=3}return!1}}return!0}const t="quikdown-",n="§CB",r={"&":"&","<":"<",">":">",'"':""","'":"'"},o={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 c(c,a={}){if(!c||"string"!=typeof c)return"";const{fence_plugin:i,inline_styles:s=!1,bidirectional:u=!1,lazy_linefeeds:d=!1,allow_unsafe_html:f=!1}=a,$=function(e,n){return function(r,o=""){if(e){let e=n[r];return e||o?(o&&o.includes("text-align")&&e&&e.includes("text-align")&&(e=e.replace(/text-align:[^;]+;?/,"").trim(),e&&!e.endsWith(";")&&(e+=";")),` style="${o?e?`${e}${o}`:o:e}"`):""}{const e=` class="${t}${r}"`;return o?`${e} style="${o}"`:e}}}(s,o);function g(e){return e.replace(/[&<>"']/g,e=>r[e])}const p=u?e=>` data-qd="${g(e)}"`:()=>"";function h(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 m=c;const b=[],q=[];m=m.replace(/^(```|~~~)([^\n]*)\n([\s\S]*?)^\1$/gm,(e,t,r,o)=>{const c=`${n}${b.length}§`,a=r?r.trim():"";return i&&i.render&&"function"==typeof i.render?b.push({lang:a,code:o.trimEnd(),custom:!0,fence:t,hasReverse:!!i.reverse}):b.push({lang:a,code:g(o.trimEnd()),custom:!1,fence:t}),c}),m=m.replace(/`([^`]+)`/g,(e,t)=>{const n=`§IC${q.length}§`;return q.push(g(t)),n}),f||(m=g(m)),m=function(e,t){const n=e.split("\n"),r=[];let o=!1,c=[];for(let e=0;e<n.length;e++){const a=n[e].trim();if(a.includes("|")&&(a.startsWith("|")||/[^\\|]/.test(a)))o||(o=!0,c=[]),c.push(a);else{if(o){const e=l(c,t);e?r.push(e):r.push(...c),o=!1,c=[]}r.push(n[e])}}if(o&&c.length>0){const e=l(c,t);e?r.push(e):r.push(...c)}return r.join("\n")}(m,$),m=function(t,n,r){const o=t.split("\n"),c=[];let a=0;for(;a<o.length;){const t=o[a];let l=0;for(;l<t.length&&l<7&&"#"===t[l];)l++;if(l>=1&&l<=6&&" "===t[l]){const e=t.slice(l+1).replace(/\s*#+\s*$/,""),o="h"+l;c.push(`<${o}${n(o)}${r("#".repeat(l))}>${e}</${o}>`),a++;continue}e(t)?(c.push(`<hr${n("hr")}>`),a++):/^>\s+/.test(t)?(c.push(`<blockquote${n("blockquote")}>${t.replace(/^>\s+/,"")}</blockquote>`),a++):(c.push(t),a++)}let l=c.join("\n");return l=l.replace(/<\/blockquote>\n<blockquote>/g,"\n"),l}(m,$,p),m=function(e,n,r,o){const c=e.split("\n"),a=[],l=[],i=e=>e.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[e])),s=o?e=>` data-qd="${i(e)}"`:()=>"";for(let e=0;e<c.length;e++){const o=c[e],i=o.match(/^(\s*)([*\-+]|\d+\.)\s+(.+)$/);if(i){const[,e,o,c]=i,u=Math.floor(e.length/2),d=/^\d+\./.test(o),f=d?"ol":"ul";let $=c,g="";const p=c.match(/^\[([x ])\]\s+(.*)$/i);if(p&&!d){const[,e,n]=p,o="x"===e.toLowerCase();$=`<input type="checkbox"${r?' style="margin-right:.5em"':` class="${t}task-checkbox"`}${o?" checked":""} disabled> ${n}`,g=r?' style="list-style:none"':` class="${t}task-item"`}for(;l.length>u+1;){const e=l.pop();a.push(`</${e.type}>`)}if(l.length===u)l.push({type:f,level:u}),a.push(`<${f}${n(f)}>`);else if(l.length===u+1){const e=l[l.length-1];e.type!==f&&(a.push(`</${e.type}>`),l.pop(),l.push({type:f,level:u}),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")}(m,$,s,u),m=m.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(e,t,n)=>{const r=h(n,a.allow_unsafe_urls),o=u&&t?` data-qd-alt="${g(t)}"`:"",c=u?` data-qd-src="${g(n)}"`:"";return`<img${$("img")} src="${r}" alt="${t}"${o}${c}${p("!")}>`}),m=m.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>{const r=h(n,a.allow_unsafe_urls),o=/^https?:\/\//i.test(r)?' rel="noopener noreferrer"':"",c=u?` data-qd-text="${g(t)}"`:"";return`<a${$("a")} href="${r}"${o}${c}${p("[")}>${t}</a>`}),m=m.replace(/(^|\s)(https?:\/\/[^\s<]+)/g,(e,t,n)=>{const r=h(n,a.allow_unsafe_urls);return`${t}<a${$("a")} href="${r}" rel="noopener noreferrer">${n}</a>`});const x=[];m=m.replace(/<[^>]+>/g,e=>(x.push(e),`%%T${x.length-1}%%`));if([[/\*\*(.+?)\*\*/g,"strong","**"],[/__(.+?)__/g,"strong","__"],[/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g,"em","*"],[/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g,"em","_"],[/~~(.+?)~~/g,"del","~~"]].forEach(([e,t,n])=>{m=m.replace(e,`<${t}${$(t)}${p(n)}>$1</${t}>`)}),m=m.replace(/%%T(\d+)%%/g,(e,t)=>x[t]),d){const e=[];let t=0;m=m.replace(/<(table|[uo]l)[^>]*>[\s\S]*?<\/\1>/g,n=>(e[t]=n,`§B${t++}§`)),m=m.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)=>m=m.replace(`§B${t}§`,e)),m="<p>"+m+"</p>"}else m=m.replace(/ {2}$/gm,`<br${$("br")}>`),m=m.replace(/\n\n+/g,(e,t)=>m.substring(0,t).match(/<\/(h[1-6]|blockquote|ul|ol|table|pre|hr)>$/)?"<p>":"</p><p>"),m="<p>"+m+"</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>(${n}\\d+§)</p>`,"g"),"$1"]].forEach(([e,t])=>{m=m.replace(e,t)}),m=m.replace(/(<\/(?:h[1-6]|blockquote|ul|ol|table|pre|hr)>)\n([^<])/g,"$1\n<p>$2"),b.forEach((e,t)=>{let r;if(e.custom&&i&&i.render)if(r=i.render(e.code,e.lang),void 0===r){const t=!s&&e.lang?` class="language-${e.lang}"`:"",n=s?$("code"):t,o=u&&e.lang?` data-qd-lang="${g(e.lang)}"`:"",c=u?` data-qd-fence="${g(e.fence)}"`:"";r=`<pre${$("pre")}${c}${o}><code${n}>${g(e.code)}</code></pre>`}else u&&(r=r.replace(/^<(\w+)/,`<$1 data-qd-fence="${g(e.fence)}" data-qd-lang="${g(e.lang)}" data-qd-source="${g(e.code)}"`));else{const t=!s&&e.lang?` class="language-${e.lang}"`:"",n=s?$("code"):t,o=u&&e.lang?` data-qd-lang="${g(e.lang)}"`:"",c=u?` data-qd-fence="${g(e.fence)}"`:"";r=`<pre${$("pre")}${c}${o}><code${n}>${e.code}</code></pre>`}const o=`${n}${t}§`;m=m.replace(o,r)}),q.forEach((e,t)=>{const n=`§IC${t}§`;m=m.replace(n,`<code${$("code")}${p("`")}>${e}</code>`)}),m.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 l(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 i(e,t={}){return c(e,{...t,bidirectional:!0})}c.emitStyles=function(e="quikdown-",t="light"){const n=o,r={"#f4f4f4":"#2a2a2a","#f0f0f0":"#2a2a2a","#f2f2f2":"#2a2a2a","#ddd":"#3a3a3a","#06c":"#6db3f2",_textColor:"#e0e0e0"},c={_textColor:"#333"};let a="";for(const[o,l]of Object.entries(n)){let n=l;if("dark"===t&&r){for(const[e,t]of Object.entries(r))e.startsWith("_")||(n=n.replaceAll(e,t));["h1","h2","h3","h4","h5","h6","td","li","blockquote"].includes(o)&&(n+=`;color:${r._textColor}`)}else if("light"===t&&c){["h1","h2","h3","h4","h5","h6","td","li","blockquote"].includes(o)&&(n+=`;color:${c._textColor}`)}a+=`.${e}${o} { ${n} }\n`}return a},c.configure=function(e){return function(t){return c(t,e)}},c.version="1.2.10","undefined"!=typeof module&&module.exports&&(module.exports=c),"undefined"!=typeof window&&(window.quikdown=c),Object.keys(c).forEach(e=>{"configure"!==e&&(i[e]=c[e])}),i.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 u=a||"`";return`${u}${l}${u}`;case"pre":const d=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||d;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`${d}${f}\n${$}\n${d}\n\n`;const g=e.querySelector("code");return`${d}${f}\n${(g?g.textContent:l).trimEnd()}\n${d}\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},i.configure=function(e){const t=c.configure({...e,bidirectional:!0});return function(e){return t(e)}},"undefined"!=typeof module&&module.exports&&(module.exports=i),"undefined"!=typeof window&&(window.quikdown_bd=i);export{i as default};
|
|
7
|
+
function e(e){if(e.length<3)return!1;for(let t=0;t<e.length;t++){const n=e[t];if("-"!==n){if(" "===n||"\t"===n){for(let n=t+1;n<e.length;n++)if(" "!==e[n]&&"\t"!==e[n])return!1;return t>=3}return!1}}return!0}const t="quikdown-",n="§CB",r="§HT",o={href:1,src:1,action:1,formaction:1},c={"&":"&","<":"<",">":">",'"':""","'":"'"},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 l(l,s={}){if(!l||"string"!=typeof l)return"";const{fence_plugin:u,inline_styles:d=!1,bidirectional:f=!1,lazy_linefeeds:$=!1,allow_unsafe_html:g=!1}=s,p=function(e,n){return function(r,o=""){if(e){let e=n[r];return e||o?(o&&o.includes("text-align")&&e&&e.includes("text-align")&&(e=e.replace(/text-align:[^;]+;?/,"").trim(),e&&!e.endsWith(";")&&(e+=";")),` style="${o?e?`${e}${o}`:o:e}"`):""}{const e=` class="${t}${r}"`;return o?`${e} style="${o}"`:e}}}(d,a);function h(e){return e.replace(/[&<>"']/g,e=>c[e])}const m=f?e=>` data-qd="${h(e)}"`:()=>"";function b(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 q=l;const x=[],y=[];q=q.replace(/^(```|~~~)([^\n]*)\n([\s\S]*?)^\1$/gm,(e,t,r,o)=>{const c=`${n}${x.length}§`,a=r?r.trim():"";return u&&u.render&&"function"==typeof u.render?x.push({lang:a,code:o.trimEnd(),custom:!0,fence:t,hasReverse:!!u.reverse}):x.push({lang:a,code:h(o.trimEnd()),custom:!1,fence:t}),c}),q=q.replace(/`([^`]+)`/g,(e,t)=>{const n=`§IC${y.length}§`;return y.push(h(t)),n});const _=[],w=Array.isArray(g)?Object.fromEntries(g.map(e=>[e,1])):g&&"object"==typeof g?g:null;w&&(q=q.replace(/<!--[\s\S]*?-->/g,e=>{const t=_.length;return _.push(e),`${r}${t}§`}),q=q.replace(/<\/?([a-zA-Z][a-zA-Z0-9]*)\b[^>]*\/?>/g,(e,t)=>{if(t.toLowerCase()in w){const t=function(e){if(!/\s/.test(e.replace(/<\/?[a-zA-Z][a-zA-Z0-9]*/,"").replace(/\/?>$/,"")))return e;const t=e.match(/^(<\/?[a-zA-Z][a-zA-Z0-9]*)([\s\S]*?)(\/?>)$/);if(!t)return e;const[,n,r,c]=t,a=/([a-zA-Z_][\w\-.:]*)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+)))?/g,l=[];let s;for(;null!==(s=a.exec(r));){const e=s[1],t=void 0!==s[2]?s[2]:void 0!==s[3]?s[3]:s[4];if(!/^on/i.test(e))if(void 0===t)l.push(e);else{let n=t;e.toLowerCase()in o&&(n=b(t)),l.push(`${e}="${n}"`)}}return n+(l.length?" "+l.join(" "):"")+c}(e),n=_.length;return _.push(t),`${r}${n}§`}return e})),!0!==g&&(q=h(q)),w&&_.forEach((e,t)=>{q=q.replace(`${r}${t}§`,e)}),q=function(e,t){const n=e.split("\n"),r=[];let o=!1,c=[];for(let e=0;e<n.length;e++){const a=n[e].trim();if(a.includes("|")&&(a.startsWith("|")||/[^\\|]/.test(a)))o||(o=!0,c=[]),c.push(a);else{if(o){const e=i(c,t);e?r.push(e):r.push(...c),o=!1,c=[]}r.push(n[e])}}if(o&&c.length>0){const e=i(c,t);e?r.push(e):r.push(...c)}return r.join("\n")}(q,p),q=function(t,n,r){const o=t.split("\n"),c=[];let a=0;for(;a<o.length;){const t=o[a];if(/^\[\/\/\]: #/.test(t)){a++;continue}let l=0;for(;l<t.length&&l<7&&"#"===t[l];)l++;if(l>=1&&l<=6&&" "===t[l]){const e=t.slice(l+1).replace(/\s*#+\s*$/,""),o="h"+l;c.push(`<${o}${n(o)}${r("#".repeat(l))}>${e}</${o}>`),a++;continue}e(t)?(c.push(`<hr${n("hr")}>`),a++):/^>\s+/.test(t)?(c.push(`<blockquote${n("blockquote")}>${t.replace(/^>\s+/,"")}</blockquote>`),a++):(c.push(t),a++)}let l=c.join("\n");return l=l.replace(/<\/blockquote>\n<blockquote>/g,"\n"),l}(q,p,m),q=function(e,n,r,o){const c=e.split("\n"),a=[],l=[],s=e=>e.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[e])),i=o?e=>` data-qd="${s(e)}"`:()=>"";for(let e=0;e<c.length;e++){const o=c[e],s=o.match(/^(\s*)([*\-+]|\d+\.)\s+(.+)$/);if(s){const[,e,o,c]=s,u=Math.floor(e.length/2),d=/^\d+\./.test(o),f=d?"ol":"ul";let $=c,g="";const p=c.match(/^\[([x ])\]\s+(.*)$/i);if(p&&!d){const[,e,n]=p,o="x"===e.toLowerCase();$=`<input type="checkbox"${r?' style="margin-right:.5em"':` class="${t}task-checkbox"`}${o?" checked":""} disabled> ${n}`,g=r?' style="list-style:none"':` class="${t}task-item"`}for(;l.length>u+1;){const e=l.pop();a.push(`</${e.type}>`)}if(l.length===u)l.push({type:f,level:u}),a.push(`<${f}${n(f)}>`);else if(l.length===u+1){const e=l[l.length-1];e.type!==f&&(a.push(`</${e.type}>`),l.pop(),l.push({type:f,level:u}),a.push(`<${f}${n(f)}>`))}const h=g||n("li");a.push(`<li${h}${i(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")}(q,p,d,f),q=q.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(e,t,n)=>{const r=b(n,s.allow_unsafe_urls),o=f&&t?` data-qd-alt="${h(t)}"`:"",c=f?` data-qd-src="${h(n)}"`:"";return`<img${p("img")} src="${r}" alt="${t}"${o}${c}${m("!")}>`}),q=q.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>{const r=b(n,s.allow_unsafe_urls),o=/^https?:\/\//i.test(r)?' rel="noopener noreferrer"':"",c=f?` data-qd-text="${h(t)}"`:"";return`<a${p("a")} href="${r}"${o}${c}${m("[")}>${t}</a>`}),q=q.replace(/(^|\s)(https?:\/\/[^\s<]+)/g,(e,t,n)=>{const r=b(n,s.allow_unsafe_urls);return`${t}<a${p("a")} href="${r}" rel="noopener noreferrer">${n}</a>`});const k=[];q=q.replace(/<[^>]+>/g,e=>(k.push(e),`%%T${k.length-1}%%`));if([[/\*\*(.+?)\*\*/g,"strong","**"],[/__(.+?)__/g,"strong","__"],[/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g,"em","*"],[/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g,"em","_"],[/~~(.+?)~~/g,"del","~~"]].forEach(([e,t,n])=>{q=q.replace(e,`<${t}${p(t)}${m(n)}>$1</${t}>`)}),q=q.replace(/%%T(\d+)%%/g,(e,t)=>k[t]),$){const e=[];let t=0;q=q.replace(/<(table|[uo]l)[^>]*>[\s\S]*?<\/\1>/g,n=>(e[t]=n,`§B${t++}§`)),q=q.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${p("br")}>`).replace(/§N§/g,"\n").replace(/§P§/g,"</p><p>"),e.forEach((e,t)=>q=q.replace(`§B${t}§`,e)),q="<p>"+q+"</p>"}else q=q.replace(/ {2}$/gm,`<br${p("br")}>`),q=q.replace(/\n\n+/g,(e,t)=>q.substring(0,t).match(/<\/(h[1-6]|blockquote|ul|ol|table|pre|hr)>$/)?"<p>":"</p><p>"),q="<p>"+q+"</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>(${n}\\d+§)</p>`,"g"),"$1"]].forEach(([e,t])=>{q=q.replace(e,t)}),q=q.replace(/(<\/(?:h[1-6]|blockquote|ul|ol|table|pre|hr)>)\n([^<])/g,"$1\n<p>$2"),x.forEach((e,t)=>{let r;if(e.custom&&u&&u.render)if(r=u.render(e.code,e.lang),void 0===r){const t=!d&&e.lang?` class="language-${e.lang}"`:"",n=d?p("code"):t,o=f&&e.lang?` data-qd-lang="${h(e.lang)}"`:"",c=f?` data-qd-fence="${h(e.fence)}"`:"";r=`<pre${p("pre")}${c}${o}><code${n}>${h(e.code)}</code></pre>`}else f&&(r=r.replace(/^<(\w+)/,`<$1 data-qd-fence="${h(e.fence)}" data-qd-lang="${h(e.lang)}" data-qd-source="${h(e.code)}"`));else{const t=!d&&e.lang?` class="language-${e.lang}"`:"",n=d?p("code"):t,o=f&&e.lang?` data-qd-lang="${h(e.lang)}"`:"",c=f?` data-qd-fence="${h(e.fence)}"`:"";r=`<pre${p("pre")}${c}${o}><code${n}>${e.code}</code></pre>`}const o=`${n}${t}§`;q=q.replace(o,r)}),y.forEach((e,t)=>{const n=`§IC${t}§`;q=q.replace(n,`<code${p("code")}${m("`")}>${e}</code>`)}),q.trim()}function s(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 i(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 a=`<table${t("table")}>\n`;return a+=`<thead${t("thead")}>\n`,r.forEach(e=>{a+=`<tr${t("tr")}>\n`;e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").forEach((e,n)=>{const r=c[n]&&"left"!==c[n]?`text-align:${c[n]}`:"",o=s(e.trim(),t);a+=`<th${t("th",r)}>${o}</th>\n`}),a+="</tr>\n"}),a+="</thead>\n",o.length>0&&(a+=`<tbody${t("tbody")}>\n`,o.forEach(e=>{a+=`<tr${t("tr")}>\n`;e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").forEach((e,n)=>{const r=c[n]&&"left"!==c[n]?`text-align:${c[n]}`:"",o=s(e.trim(),t);a+=`<td${t("td",r)}>${o}</td>\n`}),a+="</tr>\n"}),a+="</tbody>\n"),a+="</table>",a}function u(e,t={}){return l(e,{...t,bidirectional:!0})}l.emitStyles=function(e="quikdown-",t="light"){const n=a,r={"#f4f4f4":"#2a2a2a","#f0f0f0":"#2a2a2a","#f2f2f2":"#2a2a2a","#ddd":"#3a3a3a","#06c":"#6db3f2",_textColor:"#e0e0e0"},o={_textColor:"#333"};let c="";for(const[a,l]of Object.entries(n)){let n=l;if("dark"===t&&r){for(const[e,t]of Object.entries(r))e.startsWith("_")||(n=n.replaceAll(e,t));["h1","h2","h3","h4","h5","h6","td","li","blockquote"].includes(a)&&(n+=`;color:${r._textColor}`)}else if("light"===t&&o){["h1","h2","h3","h4","h5","h6","td","li","blockquote"].includes(a)&&(n+=`;color:${o._textColor}`)}c+=`.${e}${a} { ${n} }\n`}return c},l.configure=function(e){return function(t){return l(t,e)}},l.version="1.2.11","undefined"!=typeof module&&module.exports&&(module.exports=l),"undefined"!=typeof window&&(window.quikdown=l),Object.keys(l).forEach(e=>{"configure"!==e&&(u[e]=l[e])}),u.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 s=a||"*";return`${s}${l}${s}`;case"del":case"s":case"strike":if(!l)return"";const i=a||"~~";return`${i}${l}${i}`;case"code":if(!l)return"";const u=a||"`";return`${u}${l}${u}`;case"pre":const d=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||d;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`${d}${f}\n${$}\n${d}\n\n`;const g=e.querySelector("code");return`${d}${f}\n${(g?g.textContent:l).trimEnd()}\n${d}\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 s of e.children){if("LI"!==s.tagName)continue;let e=s.getAttribute("data-qd")||(t?`${a}.`:"-");const i=s.querySelector('input[type="checkbox"]');if(i){const t=i.checked?"x":" ";e="-";let n="";for(const e of s.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 s.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},u.configure=function(e){const t=l.configure({...e,bidirectional:!0});return function(e){return t(e)}},"undefined"!=typeof module&&module.exports&&(module.exports=u),"undefined"!=typeof window&&(window.quikdown_bd=u);export{u as default};
|
|
8
8
|
//# sourceMappingURL=quikdown_bd.esm.min.js.map
|
|
Binary file
|