quikdown 1.2.11 → 1.2.12
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/dist/quikdown.cjs +2 -2
- package/dist/quikdown.dark.css +1 -1
- package/dist/quikdown.esm.js +2 -2
- package/dist/quikdown.esm.min.js +2 -2
- package/dist/quikdown.esm.min.js.gz +0 -0
- package/dist/quikdown.light.css +1 -1
- package/dist/quikdown.umd.js +2 -2
- package/dist/quikdown.umd.min.js +2 -2
- package/dist/quikdown.umd.min.js.gz +0 -0
- 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 +2 -2
- package/dist/quikdown_bd.esm.js +2 -2
- package/dist/quikdown_bd.esm.min.js +2 -2
- package/dist/quikdown_bd.esm.min.js.gz +0 -0
- package/dist/quikdown_bd.umd.js +2 -2
- package/dist/quikdown_bd.umd.min.js +2 -2
- package/dist/quikdown_bd.umd.min.js.gz +0 -0
- package/dist/quikdown_edit.cjs +2 -2
- package/dist/quikdown_edit.esm.js +2 -2
- package/dist/quikdown_edit.esm.min.js +2 -2
- package/dist/quikdown_edit.esm.min.js.gz +0 -0
- package/dist/quikdown_edit.umd.js +2 -2
- package/dist/quikdown_edit.umd.min.js +2 -2
- package/dist/quikdown_edit.umd.min.js.gz +0 -0
- 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 +1 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* quikdown_ast_html - AST to HTML Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.12
|
|
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.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});
|
|
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.12","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.12","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.12
|
|
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.12';
|
|
118
118
|
|
|
119
119
|
/** CSS class prefix used for all generated elements */
|
|
120
120
|
const CLASS_PREFIX = 'quikdown-';
|
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.12
|
|
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.12';
|
|
116
116
|
|
|
117
117
|
/** CSS class prefix used for all generated elements */
|
|
118
118
|
const CLASS_PREFIX = 'quikdown-';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* quikdown_bd - Bidirectional Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.12
|
|
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="§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};
|
|
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.12","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
|
package/dist/quikdown_bd.umd.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* quikdown_bd - Bidirectional Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.12
|
|
4
4
|
* @license BSD-2-Clause
|
|
5
5
|
* @copyright DeftIO 2025
|
|
6
6
|
*/
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
// ────────────────────────────────────────────────────────────────────
|
|
119
119
|
|
|
120
120
|
/** Build-time version stamp (injected by tools/updateVersion) */
|
|
121
|
-
const quikdownVersion = '1.2.
|
|
121
|
+
const quikdownVersion = '1.2.12';
|
|
122
122
|
|
|
123
123
|
/** CSS class prefix used for all generated elements */
|
|
124
124
|
const CLASS_PREFIX = 'quikdown-';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* quikdown_bd - Bidirectional Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.12
|
|
4
4
|
* @license BSD-2-Clause
|
|
5
5
|
* @copyright DeftIO 2025
|
|
6
6
|
*/
|
|
7
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).quikdown_bd=t()}(this,function(){"use strict";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,i={}){if(!l||"string"!=typeof l)return"";const{fence_plugin:u,inline_styles:d=!1,bidirectional:f=!1,lazy_linefeeds:$=!1,allow_unsafe_html:p=!1}=i,g=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(p)?Object.fromEntries(p.map(e=>[e,1])):p&&"object"==typeof p?p: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 i;for(;null!==(i=a.exec(r));){const e=i[1],t=void 0!==i[2]?i[2]:void 0!==i[3]?i[3]:i[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!==p&&(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=s(c,t);e?r.push(e):r.push(...c),o=!1,c=[]}r.push(n[e])}}if(o&&c.length>0){const e=s(c,t);e?r.push(e):r.push(...c)}return r.join("\n")}(q,g),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,g,m),q=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,p="";const g=c.match(/^\[([x ])\]\s+(.*)$/i);if(g&&!d){const[,e,n]=g,o="x"===e.toLowerCase();$=`<input type="checkbox"${r?' style="margin-right:.5em"':` class="${t}task-checkbox"`}${o?" checked":""} disabled> ${n}`,p=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=p||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")}(q,g,d,f),q=q.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(e,t,n)=>{const r=b(n,i.allow_unsafe_urls),o=f&&t?` data-qd-alt="${h(t)}"`:"",c=f?` data-qd-src="${h(n)}"`:"";return`<img${g("img")} src="${r}" alt="${t}"${o}${c}${m("!")}>`}),q=q.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>{const r=b(n,i.allow_unsafe_urls),o=/^https?:\/\//i.test(r)?' rel="noopener noreferrer"':"",c=f?` data-qd-text="${h(t)}"`:"";return`<a${g("a")} href="${r}"${o}${c}${m("[")}>${t}</a>`}),q=q.replace(/(^|\s)(https?:\/\/[^\s<]+)/g,(e,t,n)=>{const r=b(n,i.allow_unsafe_urls);return`${t}<a${g("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}${g(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${g("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${g("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?g("code"):t,o=f&&e.lang?` data-qd-lang="${h(e.lang)}"`:"",c=f?` data-qd-fence="${h(e.fence)}"`:"";r=`<pre${g("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?g("code"):t,o=f&&e.lang?` data-qd-lang="${h(e.lang)}"`:"",c=f?` data-qd-fence="${h(e.fence)}"`:"";r=`<pre${g("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${g("code")}${m("`")}>${e}</code>`)}),q.trim()}function i(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 s(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=i(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=i(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})}return 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 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 p=e.querySelector("code");return`${d}${f}\n${(p?p.textContent:l).trimEnd()}\n${d}\n\n`;case"blockquote":const g=a||">";return l.trim().split("\n").map(e=>`${g} ${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},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),u});
|
|
7
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).quikdown_bd=t()}(this,function(){"use strict";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,i={}){if(!l||"string"!=typeof l)return"";const{fence_plugin:u,inline_styles:d=!1,bidirectional:f=!1,lazy_linefeeds:$=!1,allow_unsafe_html:p=!1}=i,g=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(p)?Object.fromEntries(p.map(e=>[e,1])):p&&"object"==typeof p?p: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 i;for(;null!==(i=a.exec(r));){const e=i[1],t=void 0!==i[2]?i[2]:void 0!==i[3]?i[3]:i[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!==p&&(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=s(c,t);e?r.push(e):r.push(...c),o=!1,c=[]}r.push(n[e])}}if(o&&c.length>0){const e=s(c,t);e?r.push(e):r.push(...c)}return r.join("\n")}(q,g),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,g,m),q=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,p="";const g=c.match(/^\[([x ])\]\s+(.*)$/i);if(g&&!d){const[,e,n]=g,o="x"===e.toLowerCase();$=`<input type="checkbox"${r?' style="margin-right:.5em"':` class="${t}task-checkbox"`}${o?" checked":""} disabled> ${n}`,p=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=p||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")}(q,g,d,f),q=q.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(e,t,n)=>{const r=b(n,i.allow_unsafe_urls),o=f&&t?` data-qd-alt="${h(t)}"`:"",c=f?` data-qd-src="${h(n)}"`:"";return`<img${g("img")} src="${r}" alt="${t}"${o}${c}${m("!")}>`}),q=q.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>{const r=b(n,i.allow_unsafe_urls),o=/^https?:\/\//i.test(r)?' rel="noopener noreferrer"':"",c=f?` data-qd-text="${h(t)}"`:"";return`<a${g("a")} href="${r}"${o}${c}${m("[")}>${t}</a>`}),q=q.replace(/(^|\s)(https?:\/\/[^\s<]+)/g,(e,t,n)=>{const r=b(n,i.allow_unsafe_urls);return`${t}<a${g("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}${g(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${g("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${g("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?g("code"):t,o=f&&e.lang?` data-qd-lang="${h(e.lang)}"`:"",c=f?` data-qd-fence="${h(e.fence)}"`:"";r=`<pre${g("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?g("code"):t,o=f&&e.lang?` data-qd-lang="${h(e.lang)}"`:"",c=f?` data-qd-fence="${h(e.fence)}"`:"";r=`<pre${g("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${g("code")}${m("`")}>${e}</code>`)}),q.trim()}function i(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 s(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=i(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=i(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})}return 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.12","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 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 p=e.querySelector("code");return`${d}${f}\n${(p?p.textContent:l).trimEnd()}\n${d}\n\n`;case"blockquote":const g=a||">";return l.trim().split("\n").map(e=>`${g} ${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},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),u});
|
|
8
8
|
//# sourceMappingURL=quikdown_bd.umd.min.js.map
|
|
Binary file
|
package/dist/quikdown_edit.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Quikdown Editor - Drop-in Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.12
|
|
4
4
|
* @license BSD-2-Clause
|
|
5
5
|
* @copyright DeftIO 2025
|
|
6
6
|
*/
|
|
@@ -224,7 +224,7 @@ function looksLikeTableRow(line) {
|
|
|
224
224
|
// ────────────────────────────────────────────────────────────────────
|
|
225
225
|
|
|
226
226
|
/** Build-time version stamp (injected by tools/updateVersion) */
|
|
227
|
-
const quikdownVersion = '1.2.
|
|
227
|
+
const quikdownVersion = '1.2.12';
|
|
228
228
|
|
|
229
229
|
/** CSS class prefix used for all generated elements */
|
|
230
230
|
const CLASS_PREFIX = 'quikdown-';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Quikdown Editor - Drop-in Markdown Parser
|
|
3
|
-
* @version 1.2.
|
|
3
|
+
* @version 1.2.12
|
|
4
4
|
* @license BSD-2-Clause
|
|
5
5
|
* @copyright DeftIO 2025
|
|
6
6
|
*/
|
|
@@ -222,7 +222,7 @@ function looksLikeTableRow(line) {
|
|
|
222
222
|
// ────────────────────────────────────────────────────────────────────
|
|
223
223
|
|
|
224
224
|
/** Build-time version stamp (injected by tools/updateVersion) */
|
|
225
|
-
const quikdownVersion = '1.2.
|
|
225
|
+
const quikdownVersion = '1.2.12';
|
|
226
226
|
|
|
227
227
|
/** CSS class prefix used for all generated elements */
|
|
228
228
|
const CLASS_PREFIX = 'quikdown-';
|