Files
2026-07-13 12:48:55 +08:00

2 lines
16 KiB
JavaScript

var e,t;e=this,t=function(){const e=t(/[\dA-Za-z]/);function t(e){return function(t){return null!==t&&e.test(String.fromCharCode(t))}}function n(t){const n=[];let r=-1,o=0,a=0;for(;++r<t.length;){const l=t.charCodeAt(r);let u="";if(37===l&&e(t.charCodeAt(r+1))&&e(t.charCodeAt(r+2)))a=2;else if(l<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(l))||(u=String.fromCharCode(l));else if(l>55295&&l<57344){const e=t.charCodeAt(r+1);l<56320&&e>56319&&e<57344?(u=String.fromCharCode(l,e),a=1):u=""}else u=String.fromCharCode(l);u&&(n.push(t.slice(o,r),encodeURIComponent(u)),o=r+a+1,u=""),a&&(r+=a,a=0)}return n.join("")+t.slice(o)}function r(e,t){const r=String(t.identifier).toUpperCase(),o=n(r.toLowerCase()),a=e.footnoteOrder.indexOf(r);let l;-1===a?(e.footnoteOrder.push(r),e.footnoteCounts[r]=1,l=e.footnoteOrder.length):(e.footnoteCounts[r]++,l=a+1);const u=e.footnoteCounts[r],i={type:"element",tagName:"a",properties:{href:"#"+e.clobberPrefix+"fn-"+o,id:e.clobberPrefix+"fnref-"+o+(u>1?"-"+u:""),dataFootnoteRef:!0,ariaDescribedBy:["footnote-label"]},children:[{type:"text",value:String(l)}]};e.patch(t,i);const p={type:"element",tagName:"sup",properties:{},children:[i]};return e.patch(t,p),e.applyData(t,p)}function o(e,t){const n=t.referenceType;let r="]";if("collapsed"===n?r+="[]":"full"===n&&(r+="["+(t.label||t.identifier)+"]"),"imageReference"===t.type)return{type:"text",value:"!["+t.alt+r};const o=e.all(t),a=o[0];a&&"text"===a.type?a.value="["+a.value:o.unshift({type:"text",value:"["});const l=o[o.length-1];return l&&"text"===l.type?l.value+=r:o.push({type:"text",value:r}),o}function a(e){const t=e.spread;return null==t?e.children.length>1:t}t(/[!-/:-@[-`{-~\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u2E52\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/);const l=i("start"),u=i("end");function i(e){return function(t){const n=t&&t.position&&t.position[e]||{};return{line:n.line||null,column:n.column||null,offset:n.offset>-1?n.offset:null}}}function p(e){const t=String(e),n=/\r?\n|\r/g;let r=n.exec(t),o=0;const a=[];for(;r;)a.push(c(t.slice(o,r.index),o>0,!0),r[0]),o=r.index+r[0].length,r=n.exec(t);return a.push(c(t.slice(o),o>0,!1)),a.join("")}function c(e,t,n){let r=0,o=e.length;if(t){let t=e.codePointAt(r);for(;9===t||32===t;)r++,t=e.codePointAt(r)}if(n){let t=e.codePointAt(o-1);for(;9===t||32===t;)o--,t=e.codePointAt(o-1)}return o>r?e.slice(r,o):""}const s={blockquote:function(e,t){const n={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)},break:function(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:"\n"}]},code:function(e,t){const n=t.value?t.value+"\n":"",r=t.lang?t.lang.match(/^[^ \t]+(?=[ \t]|$)/):null,o={};r&&(o.className=["language-"+r]);let a={type:"element",tagName:"code",properties:o,children:[{type:"text",value:n}]};return t.meta&&(a.data={meta:t.meta}),e.patch(t,a),a=e.applyData(t,a),a={type:"element",tagName:"pre",properties:{},children:[a]},e.patch(t,a),a},delete:function(e,t){const n={type:"element",tagName:"del",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)},emphasis:function(e,t){const n={type:"element",tagName:"em",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)},footnoteReference:r,footnote:function(e,t){const n=e.footnoteById;let o=1;for(;o in n;)o++;const a=String(o);return n[a]={type:"footnoteDefinition",identifier:a,children:[{type:"paragraph",children:t.children}],position:t.position},r(e,{type:"footnoteReference",identifier:a,position:t.position})},heading:function(e,t){const n={type:"element",tagName:"h"+t.depth,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)},html:function(e,t){if(e.dangerous){const n={type:"raw",value:t.value};return e.patch(t,n),e.applyData(t,n)}return null},imageReference:function(e,t){const r=e.definition(t.identifier);if(!r)return o(e,t);const a={src:n(r.url||""),alt:t.alt};null!==r.title&&void 0!==r.title&&(a.title=r.title);const l={type:"element",tagName:"img",properties:a,children:[]};return e.patch(t,l),e.applyData(t,l)},image:function(e,t){const r={src:n(t.url)};null!==t.alt&&void 0!==t.alt&&(r.alt=t.alt),null!==t.title&&void 0!==t.title&&(r.title=t.title);const o={type:"element",tagName:"img",properties:r,children:[]};return e.patch(t,o),e.applyData(t,o)},inlineCode:function(e,t){const n={type:"text",value:t.value.replace(/\r?\n|\r/g," ")};e.patch(t,n);const r={type:"element",tagName:"code",properties:{},children:[n]};return e.patch(t,r),e.applyData(t,r)},linkReference:function(e,t){const r=e.definition(t.identifier);if(!r)return o(e,t);const a={href:n(r.url||"")};null!==r.title&&void 0!==r.title&&(a.title=r.title);const l={type:"element",tagName:"a",properties:a,children:e.all(t)};return e.patch(t,l),e.applyData(t,l)},link:function(e,t){const r={href:n(t.url)};null!==t.title&&void 0!==t.title&&(r.title=t.title);const o={type:"element",tagName:"a",properties:r,children:e.all(t)};return e.patch(t,o),e.applyData(t,o)},listItem:function(e,t,n){const r=e.all(t),o=n?function(e){let t=!1;if("list"===e.type){t=e.spread||!1;const n=e.children;let r=-1;for(;!t&&++r<n.length;)t=a(n[r])}return t}(n):a(t),l={},u=[];if("boolean"==typeof t.checked){const e=r[0];let n;e&&"element"===e.type&&"p"===e.tagName?n=e:(n={type:"element",tagName:"p",properties:{},children:[]},r.unshift(n)),n.children.length>0&&n.children.unshift({type:"text",value:" "}),n.children.unshift({type:"element",tagName:"input",properties:{type:"checkbox",checked:t.checked,disabled:!0},children:[]}),l.className=["task-list-item"]}let i=-1;for(;++i<r.length;){const e=r[i];(o||0!==i||"element"!==e.type||"p"!==e.tagName)&&u.push({type:"text",value:"\n"}),"element"!==e.type||"p"!==e.tagName||o?u.push(e):u.push(...e.children)}const p=r[r.length-1];p&&(o||"element"!==p.type||"p"!==p.tagName)&&u.push({type:"text",value:"\n"});const c={type:"element",tagName:"li",properties:l,children:u};return e.patch(t,c),e.applyData(t,c)},list:function(e,t){const n={},r=e.all(t);let o=-1;for("number"==typeof t.start&&1!==t.start&&(n.start=t.start);++o<r.length;){const e=r[o];if("element"===e.type&&"li"===e.tagName&&e.properties&&Array.isArray(e.properties.className)&&e.properties.className.includes("task-list-item")){n.className=["contains-task-list"];break}}const a={type:"element",tagName:t.ordered?"ol":"ul",properties:n,children:e.wrap(r,!0)};return e.patch(t,a),e.applyData(t,a)},paragraph:function(e,t){const n={type:"element",tagName:"p",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)},root:function(e,t){const n={type:"root",children:e.wrap(e.all(t))};return e.patch(t,n),e.applyData(t,n)},strong:function(e,t){const n={type:"element",tagName:"strong",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)},table:function(e,t){const n=e.all(t),r=n.shift(),o=[];if(r){const n={type:"element",tagName:"thead",properties:{},children:e.wrap([r],!0)};e.patch(t.children[0],n),o.push(n)}if(n.length>0){const r={type:"element",tagName:"tbody",properties:{},children:e.wrap(n,!0)},a=l(t.children[1]),i=u(t.children[t.children.length-1]);a.line&&i.line&&(r.position={start:a,end:i}),o.push(r)}const a={type:"element",tagName:"table",properties:{},children:e.wrap(o,!0)};return e.patch(t,a),e.applyData(t,a)},tableCell:function(e,t){const n={type:"element",tagName:"td",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)},tableRow:function(e,t,n){const r=n?n.children:void 0,o=0===(r?r.indexOf(t):1)?"th":"td",a=n&&"table"===n.type?n.align:void 0,l=a?a.length:t.children.length;let u=-1;const i=[];for(;++u<l;){const n=t.children[u],r={},l=a?a[u]:void 0;l&&(r.align=l);let p={type:"element",tagName:o,properties:r,children:[]};n&&(p.children=e.all(n),e.patch(n,p),p=e.applyData(t,p)),i.push(p)}const p={type:"element",tagName:"tr",properties:{},children:e.wrap(i,!0)};return e.patch(t,p),e.applyData(t,p)},text:function(e,t){const n={type:"text",value:p(String(t.value))};return e.patch(t,n),e.applyData(t,n)},thematicBreak:function(e,t){const n={type:"element",tagName:"hr",properties:{},children:[]};return e.patch(t,n),e.applyData(t,n)},toml:f,yaml:f,definition:f,footnoteDefinition:f};function f(){return null}const h=function(e){if(null==e)return y;if("string"==typeof e)return function(e){return d(t);function t(t){return t&&t.type===e}}(e);if("object"==typeof e)return Array.isArray(e)?function(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=h(e[n]);return d(r);function r(...e){let n=-1;for(;++n<t.length;)if(t[n].call(this,...e))return!0;return!1}}(e):function(e){return d(t);function t(t){let n;for(n in e)if(t[n]!==e[n])return!1;return!0}}(e);if("function"==typeof e)return d(e);throw new Error("Expected function, string, or object as test")};function d(e){return function(t,...n){return Boolean(t&&"object"==typeof t&&"type"in t&&Boolean(e.call(this,t,...n)))}}function y(){return!0}const m=function(e,t,n,r){"function"==typeof t&&"function"!=typeof n&&(r=n,n=t,t=null);const o=h(t),a=r?-1:1;!function e(l,u,i){const p=l&&"object"==typeof l?l:{};if("string"==typeof p.type){const e="string"==typeof p.tagName?p.tagName:"string"==typeof p.name?p.name:void 0;Object.defineProperty(s,"name",{value:"node ("+(c=l.type+(e?"<"+e+">":""),""+c+")")})}var c;return s;function s(){let p,c,s,f=[];if((!t||o(l,u,i[i.length-1]||null))&&(f=function(e){return Array.isArray(e)?e:"number"==typeof e?[!0,e]:[e]}(n(l,i)),!1===f[0]))return f;if(l.children&&"skip"!==f[0])for(c=(r?l.children.length:-1)+a,s=i.concat(l);c>-1&&c<l.children.length;){if(p=e(l.children[c],c,s)(),!1===p[0])return p;c="number"==typeof p[1]?p[1]:c+a}return f}}(e,void 0,[])()},g=function(e,t,n,r){"function"==typeof t&&"function"!=typeof n&&(r=n,n=t,t=null),m(e,t,(function(e,t){const r=t[t.length-1];return n(e,r?r.children.indexOf(e):null,r)}),r)},F={}.hasOwnProperty;function A(e){return String(e||"").toUpperCase()}const D={}.hasOwnProperty;function C(e,t){const n=t||{},r=n.allowDangerousHtml||!1,o={};return i.dangerous=r,i.clobberPrefix=void 0===n.clobberPrefix||null===n.clobberPrefix?"user-content-":n.clobberPrefix,i.footnoteLabel=n.footnoteLabel||"Footnotes",i.footnoteLabelTagName=n.footnoteLabelTagName||"h2",i.footnoteLabelProperties=n.footnoteLabelProperties||{className:["sr-only"]},i.footnoteBackLabel=n.footnoteBackLabel||"Back to content",i.unknownHandler=n.unknownHandler,i.passThrough=n.passThrough,i.handlers={...s,...n.handlers},i.definition=function(e){const t=Object.create(null);if(!e||!e.type)throw new Error("mdast-util-definitions expected node");return g(e,"definition",(e=>{const n=A(e.identifier);n&&!F.call(t,n)&&(t[n]=e)})),function(e){const n=A(e);return n&&F.call(t,n)?t[n]:null}}(e),i.footnoteById=o,i.footnoteOrder=[],i.footnoteCounts={},i.patch=N,i.applyData=b,i.one=function(e,t){return v(i,e,t)},i.all=function(e){return x(i,e)},i.wrap=E,i.augment=a,g(e,"footnoteDefinition",(e=>{const t=String(e.identifier).toUpperCase();D.call(o,t)||(o[t]=e)})),i;function a(e,t){if(e&&"data"in e&&e.data){const n=e.data;n.hName&&("element"!==t.type&&(t={type:"element",tagName:"",properties:{},children:[]}),t.tagName=n.hName),"element"===t.type&&n.hProperties&&(t.properties={...t.properties,...n.hProperties}),"children"in t&&t.children&&n.hChildren&&(t.children=n.hChildren)}if(e){const r="type"in e?e:{position:e};(n=r)&&n.position&&n.position.start&&n.position.start.line&&n.position.start.column&&n.position.end&&n.position.end.line&&n.position.end.column&&(t.position={start:l(r),end:u(r)})}var n;return t}function i(e,t,n,r){return Array.isArray(n)&&(r=n,n={}),a(e,{type:"element",tagName:t,properties:n||{},children:r||[]})}}function N(e,t){var n;e.position&&(t.position={start:l(n=e),end:u(n)})}function b(e,t){let n=t;if(e&&e.data){const t=e.data.hName,r=e.data.hChildren,o=e.data.hProperties;"string"==typeof t&&("element"===n.type?n.tagName=t:n={type:"element",tagName:t,properties:{},children:[]}),"element"===n.type&&o&&(n.properties={...n.properties,...o}),"children"in n&&n.children&&null!=r&&(n.children=r)}return n}function v(e,t,n){const r=t&&t.type;if(!r)throw new Error("Expected node, got `"+t+"`");return D.call(e.handlers,r)?e.handlers[r](e,t,n):e.passThrough&&e.passThrough.includes(r)?"children"in t?{...t,children:x(e,t)}:t:e.unknownHandler?e.unknownHandler(e,t,n):function(e,t){const n=t.data||{},r=!("value"in t)||D.call(n,"hProperties")||D.call(n,"hChildren")?{type:"element",tagName:"div",properties:{},children:x(e,t)}:{type:"text",value:t.value};return e.patch(t,r),e.applyData(t,r)}(e,t)}function x(e,t){const n=[];if("children"in t){const r=t.children;let o=-1;for(;++o<r.length;){const a=v(e,r[o],t);if(a){if(o&&"break"===r[o-1].type&&(Array.isArray(a)||"text"!==a.type||(a.value=a.value.replace(/^\s+/,"")),!Array.isArray(a)&&"element"===a.type)){const e=a.children[0];e&&"text"===e.type&&(e.value=e.value.replace(/^\s+/,""))}Array.isArray(a)?n.push(...a):n.push(a)}}}return n}function E(e,t){const n=[];let r=-1;for(t&&n.push({type:"text",value:"\n"});++r<e.length;)r&&n.push({type:"text",value:"\n"}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:"\n"}),n}function B(e,t){const r=C(e,t),o=r.one(e,null),a=function(e){const t=[];let r=-1;for(;++r<e.footnoteOrder.length;){const o=e.footnoteById[e.footnoteOrder[r]];if(!o)continue;const a=e.all(o),l=String(o.identifier).toUpperCase(),u=n(l.toLowerCase());let i=0;const p=[];for(;++i<=e.footnoteCounts[l];){const t={type:"element",tagName:"a",properties:{href:"#"+e.clobberPrefix+"fnref-"+u+(i>1?"-"+i:""),dataFootnoteBackref:!0,className:["data-footnote-backref"],ariaLabel:e.footnoteBackLabel},children:[{type:"text",value:"↩"}]};i>1&&t.children.push({type:"element",tagName:"sup",children:[{type:"text",value:String(i)}]}),p.length>0&&p.push({type:"text",value:" "}),p.push(t)}const c=a[a.length-1];if(c&&"element"===c.type&&"p"===c.tagName){const e=c.children[c.children.length-1];e&&"text"===e.type?e.value+=" ":c.children.push({type:"text",value:" "}),c.children.push(...p)}else a.push(...p);const s={type:"element",tagName:"li",properties:{id:e.clobberPrefix+"fn-"+u},children:e.wrap(a,!0)};e.patch(o,s),t.push(s)}if(0!==t.length)return{type:"element",tagName:"section",properties:{dataFootnotes:!0,className:["footnotes"]},children:[{type:"element",tagName:e.footnoteLabelTagName,properties:{...JSON.parse(JSON.stringify(e.footnoteLabelProperties)),id:"footnote-label"},children:[{type:"text",value:e.footnoteLabel}]},{type:"text",value:"\n"},{type:"element",tagName:"ol",properties:{},children:e.wrap(t,!0)},{type:"text",value:"\n"}]}}(r);return a&&o.children.push({type:"text",value:"\n"},a),Array.isArray(o)?{type:"root",children:o}:o}return{api:function(e){e.fromMarkdown=function(e){B(e)}}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).compromiseMarkup=t();