@aiquants/markdown-explorer 0.10.0 → 0.12.0
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/CHANGELOG.md +26 -1
- package/README.md +66 -6
- package/dist/EditSurface-BTAhzvHi.js +509 -0
- package/dist/EditSurface-Dfj6Sxxb.cjs +2 -0
- package/dist/ExplorerSplit-DekOjAUZ.cjs +1 -0
- package/dist/{ExplorerSplit-D0zf7Cr_.js → ExplorerSplit-MPHjw3nW.js} +251 -248
- package/dist/{MultiLayout-Jy9BKofx.js → MultiLayout-DtSW4rEQ.js} +4 -4
- package/dist/{MultiLayout-Bq10p3a3.cjs → MultiLayout-HMzVDYWq.cjs} +1 -1
- package/dist/{NativeScrollBar-Dt6xH5Mb.cjs → NativeScrollBar-B0AkVF3E.cjs} +1 -1
- package/dist/{NativeScrollBar-CyiyL47o.js → NativeScrollBar-CNQr7JY1.js} +1 -1
- package/dist/{TreeLayout-8pRo1ANN.js → TreeLayout-CJO9tOPq.js} +3 -3
- package/dist/{TreeLayout-kVWFEKJD.cjs → TreeLayout-_XQR-9tV.cjs} +1 -1
- package/dist/client/MarkdownExplorer.d.cts +3 -2
- package/dist/client/MarkdownExplorer.d.ts +3 -2
- package/dist/core/contracts.d.cts +17 -0
- package/dist/core/contracts.d.ts +17 -0
- package/dist/core/labels.d.cts +2 -0
- package/dist/core/labels.d.ts +2 -0
- package/dist/core/treeSettings.d.cts +2 -1
- package/dist/core/treeSettings.d.ts +2 -1
- package/dist/dataRoute-CH3yOKR0.cjs +1 -0
- package/dist/dataRoute-Pm_0ue_4.js +279 -0
- package/dist/index-DpIVKG8Y.cjs +13 -0
- package/dist/{index-CfcJEnrC.js → index-o6OpR4ND.js} +967 -907
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/dist/location-BUNWJ4eB.cjs +1 -0
- package/dist/{location-Dc1qNEGm.js → location-DWd6SQhN.js} +123 -112
- package/dist/{merge-D0aGvFKC.cjs → merge-Bs7o3GyP.cjs} +1 -1
- package/dist/{merge-SRCxtHk2.js → merge-DDJaJmMU.js} +1 -1
- package/dist/sanitizePolicy-BfUlXI5E.cjs +1 -0
- package/dist/sanitizePolicy-djLC3fRN.js +96 -0
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +143 -226
- package/dist/server.cjs +1 -1
- package/dist/server.js +548 -540
- package/docs/behavior/dom-hooks.md +2 -2
- package/docs/behavior/localization.md +1 -0
- package/docs/behavior/security.md +2 -0
- package/package.json +3 -3
- package/dist/EditSurface-1Jf0CG-f.js +0 -371
- package/dist/EditSurface-B-l3Do_C.cjs +0 -2
- package/dist/ExplorerSplit-WX8afxrQ.cjs +0 -1
- package/dist/dataRoute-8pyILcjL.cjs +0 -1
- package/dist/dataRoute-Csl1WBDz.js +0 -278
- package/dist/index-sNJrKoGN.cjs +0 -13
- package/dist/location-CRYkEWiC.cjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("node-diff3"),r=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("node-diff3"),r=require("./index-DpIVKG8Y.cjs"),R=(n,t,i,l)=>{if(t===n||t===i)return{kind:"clean",text:i};if(i===n)return{kind:"clean",text:t};const d=g.diff3Merge(t.split(`
|
|
2
2
|
`),n.split(`
|
|
3
3
|
`),i.split(`
|
|
4
4
|
`),{excludeFalseConflicts:!0}),o=[];let c=0;const u=s(l.ours),a=s(l.theirs);for(const e of d)e.ok!==void 0?o.push(...e.ok):e.conflict!==void 0&&(c+=1,o.push(`${r.CONFLICT_OURS_MARKER} ${u}`,...e.conflict.a,r.CONFLICT_SEPARATOR,...e.conflict.b,`${r.CONFLICT_THEIRS_MARKER} ${a}`));const f=o.join(`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { diff3Merge as p } from "node-diff3";
|
|
2
|
-
import { C, d as R, e as u } from "./index-
|
|
2
|
+
import { C, d as R, e as u } from "./index-o6OpR4ND.js";
|
|
3
3
|
const g = (n, o, e, l) => {
|
|
4
4
|
if (o === n || o === e) return { kind: "clean", text: e };
|
|
5
5
|
if (e === n) return { kind: "clean", text: o };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const i=require("@aiquants/markdown/embeds"),A=require("@aiquants/markdown/source-lines"),h=require("./dataRoute-CH3yOKR0.cjs"),w=512;class R extends RangeError{constructor(s){super(`[markdown-explorer] the HTML nests deeper than ${String(s)} levels`),this.name="HtmlNestingLimitError"}}const O=["script","style","noscript","template","form","button","textarea","select","option","object","embed","base","meta","link","frame","frameset"],D=["srcdoc","formaction"],z=/^(?:(?:https?|mailto|tel):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/iu,H=new Set(["left","right","center","justify","start","end"]),M=new Set(["h1","h2","h3","h4","h5","h6"]),T=1,U=3,B=7,C=8,k=Object.freeze({a:Object.freeze(["target","data-link-kind","data-doc-path","data-doc-exists","data-footnote-ref","data-footnote-backref"]),area:Object.freeze(["target"]),img:Object.freeze(["data-asset-src","data-asset-exists"]),section:Object.freeze(["data-footnotes"]),iframe:Object.freeze(["allow","allowfullscreen","frameborder","referrerpolicy"])}),x=[...new Set([...Object.values(k).flatMap(t=>t.filter(s=>s.startsWith("data-"))),A.SOURCE_LINES_ATTRIBUTE])],j=new Set(["src","href","xlink:href"]),F=/^data:/iu,G=Object.freeze({FORBID_TAGS:O,FORBID_ATTR:D,ADD_TAGS:["iframe"],ADD_ATTR:(t,s)=>t===A.SOURCE_LINES_ATTRIBUTE||k[s]?.includes(t)===!0,ADD_URI_SAFE_ATTR:x,ALLOWED_URI_REGEXP:z,ALLOW_DATA_ATTR:!1}),y=t=>{let s=null;for(const c of t.split(";")){const n=c.indexOf(":");if(n<0||c.slice(0,n).trim().toLowerCase()!=="text-align")continue;const d=c.slice(n+1).trim().toLowerCase();H.has(d)&&(s=d)}return s===null?null:`text-align: ${s}`},V=t=>t.nodeType===U?{kind:"text",text:t.nodeValue??""}:t.nodeType===C||t.nodeType===B?{kind:"ignored"}:t.nodeType===T&&t.nodeName.toLowerCase()==="a"?{kind:"link",href:t.getAttribute("href")}:{kind:"element"},P=t=>{const s=t.getAttribute("type");return s!==null&&s.trim().toLowerCase()==="checkbox"&&t.hasAttribute("disabled")},W=(t,s,c,n)=>{if(t.isSupported!==!0)throw new Error("[markdown-explorer] the HTML sanitizer cannot run in this environment");if(!Number.isSafeInteger(n)||n<=0)throw new RangeError(`[markdown-explorer] the HTML sanitizer's depth limit must be a positive integer; got ${String(n)}`);const d=Object.freeze([...s]);let E=new WeakMap,m=new WeakMap,f;const p=r=>{const e=r.parentNode===null?void 0:E.get(r.parentNode),a=e===void 0?0:e+1;if(E.set(r,a),r.nodeType===T&&a>n)throw new R(n)},_=(r,e)=>{if(r.nodeType!==T)return;const a=r;(e.tagName==="input"&&!P(a)||e.tagName==="iframe"&&i.allowedFrameUrlOf(a.getAttribute("src")?.trim(),d)===null)&&a.parentNode?.removeChild(a)},N=(r,e)=>{const a=r.nodeName.toLowerCase();if(e.attrName==="style"){const o=y(e.attrValue);o===null?e.keepAttr=!1:e.attrValue=o}else if(e.attrName==="allow"&&a==="iframe"){const o=i.reduceFrameFeatures(e.attrValue);o===null?e.keepAttr=!1:e.attrValue=o}else if(e.attrName==="referrerpolicy"&&a==="iframe"){const o=e.attrValue.trim().toLowerCase();i.EMBED_FRAME_REFERRER_POLICIES.has(o)?e.attrValue=o:e.keepAttr=!1}else e.attrName===i.EMBED_LINK_ATTRIBUTE&&a==="p"?m.set(r,r.getAttribute(i.EMBED_LINK_ATTRIBUTE)):j.has(e.attrName)&&F.test(e.attrValue)||e.attrName===A.SOURCE_LINES_ATTRIBUTE&&A.parseSourceLines(e.attrValue)===null?e.keepAttr=!1:e.attrName==="id"&&M.has(a)&&(e.forceKeepAttr=!0)},g=r=>{const e=r.getAttribute("data-asset-src");e!==null&&(r.getAttribute("data-asset-exists")!=="false"&&h.isAcceptableDocumentPath(e)?r.setAttribute("src",h.explorerAssetHref(c,e,null)):r.removeAttribute("src"))},S=(r,e,a,o)=>{if(f===void 0)return;const u=r.getAttribute(a);if(u===null)return;const l=f({kind:e,path:u});l!==void 0&&r.setAttribute(o,String(l))},L=r=>{const e=r.parentNode;if(e===null)return;const a=m.get(e);a!=null&&i.placeholderLinkOf(a,[...e.childNodes].map(V))!==null&&e.setAttribute(i.EMBED_LINK_ATTRIBUTE,a)},b=r=>{if(r.nodeType!==T)return;const e=r,a=e.nodeName.toLowerCase();a==="img"?(S(e,"asset","data-asset-src","data-asset-exists"),g(e)):a==="a"&&(S(e,"doc","data-doc-path","data-doc-exists"),L(e));const o=e.getAttribute("target");if(o===null||o.trim().toLowerCase()==="_self")return;const u=e.getAttribute("rel"),l=new Set(u===null?[]:u.split(/\s+/u).filter(I=>I!==""));l.add("noopener"),l.add("noreferrer"),e.setAttribute("rel",[...l].join(" "))};return(r,e)=>{E=new WeakMap,m=new WeakMap,f=e,t.addHook("beforeSanitizeElements",p),t.addHook("uponSanitizeElement",_),t.addHook("uponSanitizeAttribute",N),t.addHook("afterSanitizeAttributes",b);try{return t.sanitize(r,G)}finally{t.removeHook("beforeSanitizeElements",p),t.removeHook("uponSanitizeElement",_),t.removeHook("uponSanitizeAttribute",N),t.removeHook("afterSanitizeAttributes",b),f=void 0}}};exports.HtmlNestingLimitError=R;exports.MAX_HTML_NESTING_DEPTH=w;exports.createHtmlSanitizer=W;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { allowedFrameUrlOf as w, reduceFrameFeatures as L, EMBED_FRAME_REFERRER_POLICIES as O, EMBED_LINK_ATTRIBUTE as T, placeholderLinkOf as D } from "@aiquants/markdown/embeds";
|
|
2
|
+
import { SOURCE_LINES_ATTRIBUTE as p, parseSourceLines as I } from "@aiquants/markdown/source-lines";
|
|
3
|
+
import { i as z, e as x } from "./dataRoute-Pm_0ue_4.js";
|
|
4
|
+
const Z = 512;
|
|
5
|
+
class H extends RangeError {
|
|
6
|
+
constructor(s) {
|
|
7
|
+
super(`[markdown-explorer] the HTML nests deeper than ${String(s)} levels`), this.name = "HtmlNestingLimitError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const M = ["script", "style", "noscript", "template", "form", "button", "textarea", "select", "option", "object", "embed", "base", "meta", "link", "frame", "frameset"], C = ["srcdoc", "formaction"], U = /^(?:(?:https?|mailto|tel):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/iu, j = /* @__PURE__ */ new Set(["left", "right", "center", "justify", "start", "end"]), B = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]), u = 1, F = 3, G = 7, y = 8, S = Object.freeze({
|
|
11
|
+
a: Object.freeze(["target", "data-link-kind", "data-doc-path", "data-doc-exists", "data-footnote-ref", "data-footnote-backref"]),
|
|
12
|
+
area: Object.freeze(["target"]),
|
|
13
|
+
img: Object.freeze(["data-asset-src", "data-asset-exists"]),
|
|
14
|
+
section: Object.freeze(["data-footnotes"]),
|
|
15
|
+
iframe: Object.freeze(["allow", "allowfullscreen", "frameborder", "referrerpolicy"])
|
|
16
|
+
}), V = [.../* @__PURE__ */ new Set([...Object.values(S).flatMap((t) => t.filter((s) => s.startsWith("data-"))), p])], P = /* @__PURE__ */ new Set(["src", "href", "xlink:href"]), W = /^data:/iu, X = Object.freeze({
|
|
17
|
+
FORBID_TAGS: M,
|
|
18
|
+
FORBID_ATTR: C,
|
|
19
|
+
ADD_TAGS: ["iframe"],
|
|
20
|
+
ADD_ATTR: (t, s) => t === p || S[s]?.includes(t) === !0,
|
|
21
|
+
ADD_URI_SAFE_ATTR: V,
|
|
22
|
+
ALLOWED_URI_REGEXP: U,
|
|
23
|
+
ALLOW_DATA_ATTR: !1
|
|
24
|
+
}), $ = (t) => {
|
|
25
|
+
let s = null;
|
|
26
|
+
for (const l of t.split(";")) {
|
|
27
|
+
const n = l.indexOf(":");
|
|
28
|
+
if (n < 0 || l.slice(0, n).trim().toLowerCase() !== "text-align") continue;
|
|
29
|
+
const f = l.slice(n + 1).trim().toLowerCase();
|
|
30
|
+
j.has(f) && (s = f);
|
|
31
|
+
}
|
|
32
|
+
return s === null ? null : `text-align: ${s}`;
|
|
33
|
+
}, K = (t) => t.nodeType === F ? { kind: "text", text: t.nodeValue ?? "" } : t.nodeType === y || t.nodeType === G ? { kind: "ignored" } : t.nodeType === u && t.nodeName.toLowerCase() === "a" ? { kind: "link", href: t.getAttribute("href") } : { kind: "element" }, Y = (t) => {
|
|
34
|
+
const s = t.getAttribute("type");
|
|
35
|
+
return s !== null && s.trim().toLowerCase() === "checkbox" && t.hasAttribute("disabled");
|
|
36
|
+
}, v = (t, s, l, n) => {
|
|
37
|
+
if (t.isSupported !== !0) throw new Error("[markdown-explorer] the HTML sanitizer cannot run in this environment");
|
|
38
|
+
if (!Number.isSafeInteger(n) || n <= 0) throw new RangeError(`[markdown-explorer] the HTML sanitizer's depth limit must be a positive integer; got ${String(n)}`);
|
|
39
|
+
const f = Object.freeze([...s]);
|
|
40
|
+
let m = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), d;
|
|
41
|
+
const E = (r) => {
|
|
42
|
+
const e = r.parentNode === null ? void 0 : m.get(r.parentNode), a = e === void 0 ? 0 : e + 1;
|
|
43
|
+
if (m.set(r, a), r.nodeType === u && a > n) throw new H(n);
|
|
44
|
+
}, b = (r, e) => {
|
|
45
|
+
if (r.nodeType !== u) return;
|
|
46
|
+
const a = r;
|
|
47
|
+
(e.tagName === "input" && !Y(a) || e.tagName === "iframe" && w(a.getAttribute("src")?.trim(), f) === null) && a.parentNode?.removeChild(a);
|
|
48
|
+
}, h = (r, e) => {
|
|
49
|
+
const a = r.nodeName.toLowerCase();
|
|
50
|
+
if (e.attrName === "style") {
|
|
51
|
+
const o = $(e.attrValue);
|
|
52
|
+
o === null ? e.keepAttr = !1 : e.attrValue = o;
|
|
53
|
+
} else if (e.attrName === "allow" && a === "iframe") {
|
|
54
|
+
const o = L(e.attrValue);
|
|
55
|
+
o === null ? e.keepAttr = !1 : e.attrValue = o;
|
|
56
|
+
} else if (e.attrName === "referrerpolicy" && a === "iframe") {
|
|
57
|
+
const o = e.attrValue.trim().toLowerCase();
|
|
58
|
+
O.has(o) ? e.attrValue = o : e.keepAttr = !1;
|
|
59
|
+
} else e.attrName === T && a === "p" ? A.set(r, r.getAttribute(T)) : P.has(e.attrName) && W.test(e.attrValue) || e.attrName === p && I(e.attrValue) === null ? e.keepAttr = !1 : e.attrName === "id" && B.has(a) && (e.forceKeepAttr = !0);
|
|
60
|
+
}, k = (r) => {
|
|
61
|
+
const e = r.getAttribute("data-asset-src");
|
|
62
|
+
e !== null && (r.getAttribute("data-asset-exists") !== "false" && z(e) ? r.setAttribute("src", x(l, e, null)) : r.removeAttribute("src"));
|
|
63
|
+
}, N = (r, e, a, o) => {
|
|
64
|
+
if (d === void 0) return;
|
|
65
|
+
const c = r.getAttribute(a);
|
|
66
|
+
if (c === null) return;
|
|
67
|
+
const i = d({ kind: e, path: c });
|
|
68
|
+
i !== void 0 && r.setAttribute(o, String(i));
|
|
69
|
+
}, g = (r) => {
|
|
70
|
+
const e = r.parentNode;
|
|
71
|
+
if (e === null) return;
|
|
72
|
+
const a = A.get(e);
|
|
73
|
+
a != null && D(a, [...e.childNodes].map(K)) !== null && e.setAttribute(T, a);
|
|
74
|
+
}, _ = (r) => {
|
|
75
|
+
if (r.nodeType !== u) return;
|
|
76
|
+
const e = r, a = e.nodeName.toLowerCase();
|
|
77
|
+
a === "img" ? (N(e, "asset", "data-asset-src", "data-asset-exists"), k(e)) : a === "a" && (N(e, "doc", "data-doc-path", "data-doc-exists"), g(e));
|
|
78
|
+
const o = e.getAttribute("target");
|
|
79
|
+
if (o === null || o.trim().toLowerCase() === "_self") return;
|
|
80
|
+
const c = e.getAttribute("rel"), i = new Set(c === null ? [] : c.split(/\s+/u).filter((R) => R !== ""));
|
|
81
|
+
i.add("noopener"), i.add("noreferrer"), e.setAttribute("rel", [...i].join(" "));
|
|
82
|
+
};
|
|
83
|
+
return (r, e) => {
|
|
84
|
+
m = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), d = e, t.addHook("beforeSanitizeElements", E), t.addHook("uponSanitizeElement", b), t.addHook("uponSanitizeAttribute", h), t.addHook("afterSanitizeAttributes", _);
|
|
85
|
+
try {
|
|
86
|
+
return t.sanitize(r, X);
|
|
87
|
+
} finally {
|
|
88
|
+
t.removeHook("beforeSanitizeElements", E), t.removeHook("uponSanitizeElement", b), t.removeHook("uponSanitizeAttribute", h), t.removeHook("afterSanitizeAttributes", _), d = void 0;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export {
|
|
93
|
+
H,
|
|
94
|
+
Z as M,
|
|
95
|
+
v as c
|
|
96
|
+
};
|
package/dist/sanitizeWorker.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const re=require("node:worker_threads"),_=require("parse5"),L=require("@aiquants/markdown/embeds"),H=require("@aiquants/markdown/source-lines"),S=require("isomorphic-dompurify"),G=require("./dataRoute-8pyILcjL.cjs"),j=512,ne=4096,V=1024,$=Symbol("placement"),W=2,se=3,oe=new Set(["html","head","body"]),N=0,D=1,M=2,Q=3,z=4,O=5,R=6,b=7,q=8,U=9,X=10,w=-1,ae=0,ie=1,le=2,ce=3,ue=4,fe=5,Y=6,de=7,Ee=r=>{switch(r){case 9:case 10:case 12:case 13:case 32:return ae;case 47:return ie;case 62:return le;case 61:return ce;case 34:return ue;case 39:return fe;default:return Y}},Te=Uint8Array.from({length:128},(r,i)=>Ee(i)),P=60,K=47,pe=/[\t\n\f\r />="'<]/g,Ae=/["<]/g,he=/['<]/g,m=-1-M,me=Int8Array.from([[D,U,w,N,N,N,N],[D,U,w,m,m,m,m],[Q,U,w,z,M,M,M],[Q,U,w,z,m,m,m],[z,b,w,b,O,R,b],[O,O,O,O,q,O,O],[R,R,R,R,R,q,R],[D,b,w,b,b,b,b],[D,U,w,m,m,m,m],[D,U,w,m,m,m,m]].flat()),J=r=>r>=65&&r<=90||r>=97&&r<=122,ge=(r,i)=>{let u=new Int32Array(X),f=new Int32Array(X),l=0,A=0,n=0;for(;n<r.length;){if(l===0){const E=r.indexOf("<",n);if(E<0)return!1;n=E+1,r.charCodeAt(n)===K&&(n+=1),J(r.charCodeAt(n))&&(u[N]=0,l=1<<N,n+=1);continue}if((l&-230)===0&&n>=A){const E=l===1<<O?Ae:l===1<<R?he:pe;E.lastIndex=n;const a=E.exec(r);if(a===null)return!1;n=a.index,r.charCodeAt(n)===P&&(A=n+3)}const p=r.charCodeAt(n),g=p<128?Te[p]:Y;let h=0;for(let E=l;E!==0;E&=E-1){const a=31-Math.clz32(E&-E);let e=me[a*de+g],s=u[a];if(e<w&&(e=-1-e,s+=1,s>i))return!0;if(e===w)continue;const T=1<<e;((h&T)===0||s>f[e])&&(f[e]=s),h|=T}J(p)&&(r.charCodeAt(n-1)===P||r.charCodeAt(n-1)===K&&r.charCodeAt(n-2)===P)&&(h&1<<N)===0&&(f[N]=0,h|=1<<N);const I=u;u=f,f=I,l=h,n+=1}return!1};class k extends Error{status;constructor(i){super(`[markdown-explorer] the nesting guard stopped the parse: ${i}`),this.name="ParseStop",this.status=i}}const _e=(r,i,u,f)=>{if(!Number.isSafeInteger(i)||i<=0)throw new RangeError(`[markdown-explorer] the nesting guard's depth limit must be a positive safe integer; got ${String(i)}`);if(!Number.isSafeInteger(u)||u<=0)throw new RangeError(`[markdown-explorer] the nesting guard's node budget must be a positive safe integer; got ${String(u)}`);if(!Number.isSafeInteger(f)||f<=0)throw new RangeError(`[markdown-explorer] the nesting guard's attribute character budget must be a positive safe integer; got ${String(f)}`);if(ge(r,V))return{status:"too-many-attributes"};const l=i+W,A=r.length+se;let n=null,p=0,g=0,h=0,I=0;const E=t=>{if(g+=t,g>u)throw new k("too-many-nodes")},a=t=>{for(const o of t)I+=o.name.length+o.value.length;if(I>f)throw new k("too-many-attribute-characters")},e=(t,o,c,d)=>{const F={node:t,above:null,levels:o,height:0,keepsChildren:c,attributes:d,first:null,next:null,previous:null},te=t;return te[$]=F,F},s=t=>{const c=t[$];if(c===void 0)throw new Error("[markdown-explorer] the nesting guard was handed a node it did not create");return c},T=(t,o)=>{let c=o;for(let d=t;d!==null&&c>d.height;d=d.above)d.height=c,c+=d.levels;if(n!==null&&n.height>l)throw new k("too-deep")},y=t=>{const o=t.above;o?.keepsChildren&&(t.previous===null?o.first=t.next:t.previous.next=t.next,t.next!==null&&(t.next.previous=t.previous)),t.above=null,t.next=null,t.previous=null},C=(t,o)=>{if(!_.defaultTreeAdapter.isElementNode(o))return;const c=s(o),d=s(t);y(c),c.above=d,d.keepsChildren&&(c.next=d.first,d.first!==null&&(d.first.previous=c),d.first=c),o.parentNode=t,T(d,c.height+c.levels)},B={..._.defaultTreeAdapter,createDocument:()=>{const t=_.defaultTreeAdapter.createDocument();return n=e(t,0,!1,0),t},createDocumentFragment:()=>{const t=_.defaultTreeAdapter.createDocumentFragment();return e(t,0,!1,0),t},createElement:(t,o,c)=>{if(p+=1,p>A)throw new k("too-many-elements");E(1+c.length),a(c);const d=_.defaultTreeAdapter.createElement(t,o,c);return e(d,1,!(o===_.html.NS.HTML&&oe.has(t)),c.length),d},createCommentNode:t=>{if(h+=1,h>ne)throw new k("too-many-comments");return E(1),_.defaultTreeAdapter.createCommentNode(t)},setTemplateContent:(t,o)=>{_.defaultTreeAdapter.setTemplateContent(t,o);const c=s(o);c.above=s(t),T(c.above,c.height)},appendChild:C,insertBefore:(t,o)=>C(t,o),detachNode:t=>{_.defaultTreeAdapter.isElementNode(t)&&(y(s(t)),t.parentNode=null)},getFirstChild:t=>{const o=s(t);if(!o.keepsChildren)throw new Error("[markdown-explorer] the nesting guard was asked for the children of a node whose children it does not keep");return o.first===null?null:o.first.node},getChildNodes:()=>{throw new Error("[markdown-explorer] the nesting guard keeps no child lists for source locations")},onItemPop:t=>{const o=s(t);o.keepsChildren=!1,o.first=null},insertText:()=>{},insertTextBefore:()=>{},adoptAttributes:(t,o)=>{E(o.length),a(o);const c=s(t);if(c.attributes+=o.length,c.attributes>V)throw new k("too-many-attributes")}};let v;try{v=_.parse(r,{scriptingEnabled:!1,treeAdapter:B})}catch(t){if(t instanceof k)return{status:t.status};throw t}return{status:"within",depth:s(v).height-W,elements:p,nodes:g}};class Z extends RangeError{constructor(i){super(`[markdown-explorer] the HTML nests deeper than ${String(i)} levels`),this.name="HtmlNestingLimitError"}}const Se=["script","style","noscript","template","form","button","textarea","select","option","object","embed","base","meta","link","frame","frameset"],we=["srcdoc","formaction"],Ne=/^(?:(?:https?|mailto|tel):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/iu,be=new Set(["left","right","center","justify","start","end"]),Oe=new Set(["h1","h2","h3","h4","h5","h6"]),x=1,Re=3,Le=7,ke=8,ee=Object.freeze({a:Object.freeze(["target","data-link-kind","data-doc-path","data-doc-exists","data-footnote-ref","data-footnote-backref"]),area:Object.freeze(["target"]),img:Object.freeze(["data-asset-src","data-asset-exists"]),section:Object.freeze(["data-footnotes"]),iframe:Object.freeze(["allow","allowfullscreen","frameborder","referrerpolicy"])}),Ie=[...new Set([...Object.values(ee).flatMap(r=>r.filter(i=>i.startsWith("data-"))),H.SOURCE_LINES_ATTRIBUTE])],Ce=new Set(["src","href","xlink:href"]),Ue=/^data:/iu,ye=Object.freeze({FORBID_TAGS:Se,FORBID_ATTR:we,ADD_TAGS:["iframe"],ADD_ATTR:(r,i)=>r===H.SOURCE_LINES_ATTRIBUTE||ee[i]?.includes(r)===!0,ADD_URI_SAFE_ATTR:Ie,ALLOWED_URI_REGEXP:Ne,ALLOW_DATA_ATTR:!1}),De=r=>{let i=null;for(const u of r.split(";")){const f=u.indexOf(":");if(f<0||u.slice(0,f).trim().toLowerCase()!=="text-align")continue;const l=u.slice(f+1).trim().toLowerCase();be.has(l)&&(i=l)}return i===null?null:`text-align: ${i}`},Me=r=>r.nodeType===Re?{kind:"text",text:r.nodeValue??""}:r.nodeType===ke||r.nodeType===Le?{kind:"ignored"}:r.nodeType===x&&r.nodeName.toLowerCase()==="a"?{kind:"link",href:r.getAttribute("href")}:{kind:"element"},xe=r=>{const i=r.getAttribute("type");return i!==null&&i.trim().toLowerCase()==="checkbox"&&r.hasAttribute("disabled")},He=(r,i,u)=>{if(S.isSupported!==!0)throw new Error("[markdown-explorer] the HTML sanitizer cannot run in this environment");if(!Number.isSafeInteger(u)||u<=0)throw new RangeError(`[markdown-explorer] the HTML sanitizer's depth limit must be a positive integer; got ${String(u)}`);const f=Object.freeze([...r]);let l=new WeakMap,A=new WeakMap;const n=a=>{const e=a.parentNode===null?void 0:l.get(a.parentNode),s=e===void 0?0:e+1;if(l.set(a,s),a.nodeType===x&&s>u)throw new Z(u)},p=(a,e)=>{if(a.nodeType!==x)return;const s=a;(e.tagName==="input"&&!xe(s)||e.tagName==="iframe"&&L.allowedFrameUrlOf(s.getAttribute("src")?.trim(),f)===null)&&s.parentNode?.removeChild(s)},g=(a,e)=>{const s=a.nodeName.toLowerCase();if(e.attrName==="style"){const T=De(e.attrValue);T===null?e.keepAttr=!1:e.attrValue=T}else if(e.attrName==="allow"&&s==="iframe"){const T=L.reduceFrameFeatures(e.attrValue);T===null?e.keepAttr=!1:e.attrValue=T}else if(e.attrName==="referrerpolicy"&&s==="iframe"){const T=e.attrValue.trim().toLowerCase();L.EMBED_FRAME_REFERRER_POLICIES.has(T)?e.attrValue=T:e.keepAttr=!1}else e.attrName===L.EMBED_LINK_ATTRIBUTE&&s==="p"?A.set(a,a.getAttribute(L.EMBED_LINK_ATTRIBUTE)):Ce.has(e.attrName)&&Ue.test(e.attrValue)||e.attrName===H.SOURCE_LINES_ATTRIBUTE&&H.parseSourceLines(e.attrValue)===null?e.keepAttr=!1:e.attrName==="id"&&Oe.has(s)&&(e.forceKeepAttr=!0)},h=a=>{const e=a.getAttribute("data-asset-src");e!==null&&(a.getAttribute("data-asset-exists")!=="false"&&G.isAcceptableDocumentPath(e)?a.setAttribute("src",G.explorerAssetHref(i,e,null)):a.removeAttribute("src"))},I=a=>{const e=a.parentNode;if(e===null)return;const s=A.get(e);s!=null&&L.placeholderLinkOf(s,[...e.childNodes].map(Me))!==null&&e.setAttribute(L.EMBED_LINK_ATTRIBUTE,s)},E=a=>{if(a.nodeType!==x)return;const e=a,s=e.nodeName.toLowerCase();s==="img"?h(e):s==="a"&&I(e);const T=e.getAttribute("target");if(T===null||T.trim().toLowerCase()==="_self")return;const y=e.getAttribute("rel"),C=new Set(y===null?[]:y.split(/\s+/u).filter(B=>B!==""));C.add("noopener"),C.add("noreferrer"),e.setAttribute("rel",[...C].join(" "))};return a=>{l=new WeakMap,A=new WeakMap,S.addHook("beforeSanitizeElements",n),S.addHook("uponSanitizeElement",p),S.addHook("uponSanitizeAttribute",g),S.addHook("afterSanitizeAttributes",E);try{return S.sanitize(a,ye)}finally{S.removeHook("beforeSanitizeElements",n),S.removeHook("uponSanitizeElement",p),S.removeHook("uponSanitizeAttribute",g),S.removeHook("afterSanitizeAttributes",E)}}},Be=r=>{if(r===null||typeof r!="object")return!1;const{id:i,input:u}=r;if(typeof i!="number"||u===null||typeof u!="object")return!1;const{html:f,iframeHosts:l,dataPath:A,maxNodes:n,maxAttributeChars:p,maxSanitizedChars:g}=u;return typeof f=="string"&&Array.isArray(l)&&l.every(h=>typeof h=="string")&&typeof A=="string"&&A!==""&&[n,p,g].every(h=>Number.isSafeInteger(h)&&h>0)},ze=()=>{const r=re.parentPort;if(r===null)throw new Error("[markdown-explorer] the sanitizer worker must run in a worker thread");const i=new Map;r.on("message",u=>{if(!Be(u))throw new TypeError("[markdown-explorer] the sanitizer worker received a message that is not a job");const{id:f,input:l}=u;let A;try{if(_e(l.html,j,l.maxNodes,l.maxAttributeChars).status!=="within"){r.postMessage({id:f,output:{status:"too-large"}});return}const n=JSON.stringify([l.iframeHosts,l.dataPath]);let p=i.get(n);p===void 0&&(p=He(l.iframeHosts,l.dataPath,j),i.set(n,p));const g=p(l.html);A=g.length>l.maxSanitizedChars?{status:"too-large"}:{status:"sanitized",html:g}}catch(n){A=n instanceof Z?{status:"too-large"}:{status:"error",message:n instanceof Error?`${n.name}: ${n.message}`:String(n)}}r.postMessage({id:f,output:A})}),r.postMessage({ready:!0})};ze();
|
|
1
|
+
"use strict";const J=require("node:worker_threads"),W=require("isomorphic-dompurify"),M=require("./sanitizePolicy-BfUlXI5E.cjs"),A=require("parse5"),K=4096,P=1024,B=Symbol("placement"),G=2,Y=3,Z=new Set(["html","head","body"]),S=0,v=1,I=2,z=3,U=4,C=5,N=6,w=7,F=8,b=9,Q=10,m=-1,ee=0,te=1,re=2,ne=3,se=4,oe=5,q=6,ae=7,ie=t=>{switch(t){case 9:case 10:case 12:case 13:case 32:return ee;case 47:return te;case 62:return re;case 61:return ne;case 34:return se;case 39:return oe;default:return q}},ce=Uint8Array.from({length:128},(t,i)=>ie(i)),x=60,V=47,le=/[\t\n\f\r />="'<]/g,ue=/["<]/g,fe=/['<]/g,f=-1-I,de=Int8Array.from([[v,b,m,S,S,S,S],[v,b,m,f,f,f,f],[z,b,m,U,I,I,I],[z,b,m,U,f,f,f],[U,w,m,w,C,N,w],[C,C,C,C,F,C,C],[N,N,N,N,N,F,N],[v,w,m,w,w,w,w],[v,b,m,f,f,f,f],[v,b,m,f,f,f,f]].flat()),$=t=>t>=65&&t<=90||t>=97&&t<=122,Ee=(t,i)=>{let c=new Int32Array(Q),l=new Int32Array(Q),o=0,p=0,n=0;for(;n<t.length;){if(o===0){const u=t.indexOf("<",n);if(u<0)return!1;n=u+1,t.charCodeAt(n)===V&&(n+=1),$(t.charCodeAt(n))&&(c[S]=0,o=1<<S,n+=1);continue}if((o&-230)===0&&n>=p){const u=o===1<<C?ue:o===1<<N?fe:le;u.lastIndex=n;const _=u.exec(t);if(_===null)return!1;n=_.index,t.charCodeAt(n)===x&&(p=n+3)}const d=t.charCodeAt(n),g=d<128?ce[d]:q;let h=0;for(let u=o;u!==0;u&=u-1){const _=31-Math.clz32(u&-u);let T=de[_*ae+g],E=c[_];if(T<m&&(T=-1-T,E+=1,E>i))return!0;if(T===m)continue;const L=1<<T;((h&L)===0||E>l[T])&&(l[T]=E),h|=L}$(d)&&(t.charCodeAt(n-1)===x||t.charCodeAt(n-1)===V&&t.charCodeAt(n-2)===x)&&(h&1<<S)===0&&(l[S]=0,h|=1<<S);const y=c;c=l,l=y,o=h,n+=1}return!1};class O extends Error{status;constructor(i){super(`[markdown-explorer] the nesting guard stopped the parse: ${i}`),this.name="ParseStop",this.status=i}}const he=(t,i,c,l)=>{if(!Number.isSafeInteger(i)||i<=0)throw new RangeError(`[markdown-explorer] the nesting guard's depth limit must be a positive safe integer; got ${String(i)}`);if(!Number.isSafeInteger(c)||c<=0)throw new RangeError(`[markdown-explorer] the nesting guard's node budget must be a positive safe integer; got ${String(c)}`);if(!Number.isSafeInteger(l)||l<=0)throw new RangeError(`[markdown-explorer] the nesting guard's attribute character budget must be a positive safe integer; got ${String(l)}`);if(Ee(t,P))return{status:"too-many-attributes"};const o=i+G,p=t.length+Y;let n=null,d=0,g=0,h=0,y=0;const u=e=>{if(g+=e,g>c)throw new O("too-many-nodes")},_=e=>{for(const r of e)y+=r.name.length+r.value.length;if(y>l)throw new O("too-many-attribute-characters")},T=(e,r,s,a)=>{const D={node:e,above:null,levels:r,height:0,keepsChildren:s,attributes:a,first:null,next:null,previous:null},j=e;return j[B]=D,D},E=e=>{const s=e[B];if(s===void 0)throw new Error("[markdown-explorer] the nesting guard was handed a node it did not create");return s},L=(e,r)=>{let s=r;for(let a=e;a!==null&&s>a.height;a=a.above)a.height=s,s+=a.levels;if(n!==null&&n.height>o)throw new O("too-deep")},k=e=>{const r=e.above;r?.keepsChildren&&(e.previous===null?r.first=e.next:e.previous.next=e.next,e.next!==null&&(e.next.previous=e.previous)),e.above=null,e.next=null,e.previous=null},R=(e,r)=>{if(!A.defaultTreeAdapter.isElementNode(r))return;const s=E(r),a=E(e);k(s),s.above=a,a.keepsChildren&&(s.next=a.first,a.first!==null&&(a.first.previous=s),a.first=s),r.parentNode=e,L(a,s.height+s.levels)},X={...A.defaultTreeAdapter,createDocument:()=>{const e=A.defaultTreeAdapter.createDocument();return n=T(e,0,!1,0),e},createDocumentFragment:()=>{const e=A.defaultTreeAdapter.createDocumentFragment();return T(e,0,!1,0),e},createElement:(e,r,s)=>{if(d+=1,d>p)throw new O("too-many-elements");u(1+s.length),_(s);const a=A.defaultTreeAdapter.createElement(e,r,s);return T(a,1,!(r===A.html.NS.HTML&&Z.has(e)),s.length),a},createCommentNode:e=>{if(h+=1,h>K)throw new O("too-many-comments");return u(1),A.defaultTreeAdapter.createCommentNode(e)},setTemplateContent:(e,r)=>{A.defaultTreeAdapter.setTemplateContent(e,r);const s=E(r);s.above=E(e),L(s.above,s.height)},appendChild:R,insertBefore:(e,r)=>R(e,r),detachNode:e=>{A.defaultTreeAdapter.isElementNode(e)&&(k(E(e)),e.parentNode=null)},getFirstChild:e=>{const r=E(e);if(!r.keepsChildren)throw new Error("[markdown-explorer] the nesting guard was asked for the children of a node whose children it does not keep");return r.first===null?null:r.first.node},getChildNodes:()=>{throw new Error("[markdown-explorer] the nesting guard keeps no child lists for source locations")},onItemPop:e=>{const r=E(e);r.keepsChildren=!1,r.first=null},insertText:()=>{},insertTextBefore:()=>{},adoptAttributes:(e,r)=>{u(r.length),_(r);const s=E(e);if(s.attributes+=r.length,s.attributes>P)throw new O("too-many-attributes")}};let H;try{H=A.parse(t,{scriptingEnabled:!1,treeAdapter:X})}catch(e){if(e instanceof O)return{status:e.status};throw e}return{status:"within",depth:E(H).height-G,elements:d,nodes:g}},pe=t=>{if(t===null||typeof t!="object")return!1;const{id:i,input:c}=t;if(typeof i!="number"||c===null||typeof c!="object")return!1;const{html:l,iframeHosts:o,dataPath:p,maxNodes:n,maxAttributeChars:d,maxSanitizedChars:g}=c;return typeof l=="string"&&Array.isArray(o)&&o.every(h=>typeof h=="string")&&typeof p=="string"&&p!==""&&[n,d,g].every(h=>Number.isSafeInteger(h)&&h>0)},Te=()=>{const t=J.parentPort;if(t===null)throw new Error("[markdown-explorer] the sanitizer worker must run in a worker thread");const i=new Map;t.on("message",c=>{if(!pe(c))throw new TypeError("[markdown-explorer] the sanitizer worker received a message that is not a job");const{id:l,input:o}=c;let p;try{if(he(o.html,M.MAX_HTML_NESTING_DEPTH,o.maxNodes,o.maxAttributeChars).status!=="within"){t.postMessage({id:l,output:{status:"too-large"}});return}const n=JSON.stringify([o.iframeHosts,o.dataPath]);let d=i.get(n);d===void 0&&(d=M.createHtmlSanitizer(W,o.iframeHosts,o.dataPath,M.MAX_HTML_NESTING_DEPTH),i.set(n,d));const g=d(o.html);p=g.length>o.maxSanitizedChars?{status:"too-large"}:{status:"sanitized",html:g}}catch(n){p=n instanceof M.HtmlNestingLimitError?{status:"too-large"}:{status:"error",message:n instanceof Error?`${n.name}: ${n.message}`:String(n)}}t.postMessage({id:l,output:p})}),t.postMessage({ready:!0})};Te();
|
package/dist/sanitizeWorker.js
CHANGED
|
@@ -1,282 +1,199 @@
|
|
|
1
|
-
import { parentPort as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const G = 512, fe = 4096, j = 1024, V = /* @__PURE__ */ Symbol("placement"), W = 2, de = 3, pe = /* @__PURE__ */ new Set(["html", "head", "body"]), w = 0, D = 1, M = 2, Q = 3, z = 4, O = 5, k = 6, b = 7, $ = 8, I = 9, X = 10, _ = -1, Ee = 0, me = 1, Te = 2, he = 3, Ae = 4, ge = 5, Y = 6, Se = 7, _e = (r) => {
|
|
8
|
-
switch (r) {
|
|
1
|
+
import { parentPort as W } from "node:worker_threads";
|
|
2
|
+
import q from "isomorphic-dompurify";
|
|
3
|
+
import { M as D, c as K, H as Y } from "./sanitizePolicy-djLC3fRN.js";
|
|
4
|
+
import { defaultTreeAdapter as w, parse as Z, html as ee } from "parse5";
|
|
5
|
+
const te = 4096, P = 1024, B = /* @__PURE__ */ Symbol("placement"), G = 2, re = 3, ne = /* @__PURE__ */ new Set(["html", "head", "body"]), A = 0, L = 1, M = 2, z = 3, U = 4, C = 5, N = 6, _ = 7, F = 8, b = 9, Q = 10, T = -1, oe = 0, se = 1, ae = 2, ie = 3, ce = 4, le = 5, j = 6, ue = 7, fe = (t) => {
|
|
6
|
+
switch (t) {
|
|
9
7
|
case 9:
|
|
10
8
|
case 10:
|
|
11
9
|
case 12:
|
|
12
10
|
case 13:
|
|
13
11
|
case 32:
|
|
14
|
-
return
|
|
12
|
+
return oe;
|
|
15
13
|
case 47:
|
|
16
|
-
return
|
|
14
|
+
return se;
|
|
17
15
|
case 62:
|
|
18
|
-
return
|
|
16
|
+
return ae;
|
|
19
17
|
case 61:
|
|
20
|
-
return
|
|
18
|
+
return ie;
|
|
21
19
|
case 34:
|
|
22
|
-
return
|
|
20
|
+
return ce;
|
|
23
21
|
case 39:
|
|
24
|
-
return
|
|
22
|
+
return le;
|
|
25
23
|
default:
|
|
26
|
-
return
|
|
24
|
+
return j;
|
|
27
25
|
}
|
|
28
|
-
},
|
|
26
|
+
}, he = Uint8Array.from({ length: 128 }, (t, i) => fe(i)), I = 60, V = 47, Ee = /[\t\n\f\r />="'<]/g, de = /["<]/g, pe = /['<]/g, f = -1 - M, ge = Int8Array.from(
|
|
29
27
|
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
[
|
|
36
|
-
[
|
|
37
|
-
[
|
|
38
|
-
[
|
|
39
|
-
[
|
|
28
|
+
[L, b, T, A, A, A, A],
|
|
29
|
+
[L, b, T, f, f, f, f],
|
|
30
|
+
[z, b, T, U, M, M, M],
|
|
31
|
+
[z, b, T, U, f, f, f],
|
|
32
|
+
[U, _, T, _, C, N, _],
|
|
33
|
+
[C, C, C, C, F, C, C],
|
|
34
|
+
[N, N, N, N, N, F, N],
|
|
35
|
+
[L, _, T, _, _, _, _],
|
|
36
|
+
[L, b, T, f, f, f, f],
|
|
37
|
+
[L, b, T, f, f, f, f]
|
|
40
38
|
].flat()
|
|
41
|
-
),
|
|
42
|
-
let
|
|
43
|
-
for (; n <
|
|
44
|
-
if (
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
n =
|
|
39
|
+
), $ = (t) => t >= 65 && t <= 90 || t >= 97 && t <= 122, me = (t, i) => {
|
|
40
|
+
let c = new Int32Array(Q), l = new Int32Array(Q), s = 0, p = 0, n = 0;
|
|
41
|
+
for (; n < t.length; ) {
|
|
42
|
+
if (s === 0) {
|
|
43
|
+
const u = t.indexOf("<", n);
|
|
44
|
+
if (u < 0) return !1;
|
|
45
|
+
n = u + 1, t.charCodeAt(n) === V && (n += 1), $(t.charCodeAt(n)) && (c[A] = 0, s = 1 << A, n += 1);
|
|
48
46
|
continue;
|
|
49
47
|
}
|
|
50
|
-
if ((
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
n =
|
|
48
|
+
if ((s & -230) === 0 && n >= p) {
|
|
49
|
+
const u = s === 1 << C ? de : s === 1 << N ? pe : Ee;
|
|
50
|
+
u.lastIndex = n;
|
|
51
|
+
const S = u.exec(t);
|
|
52
|
+
if (S === null) return !1;
|
|
53
|
+
n = S.index, t.charCodeAt(n) === I && (p = n + 3);
|
|
56
54
|
}
|
|
57
|
-
const
|
|
58
|
-
let
|
|
59
|
-
for (let
|
|
60
|
-
const
|
|
61
|
-
let
|
|
62
|
-
if (
|
|
55
|
+
const h = t.charCodeAt(n), m = h < 128 ? he[h] : j;
|
|
56
|
+
let d = 0;
|
|
57
|
+
for (let u = s; u !== 0; u &= u - 1) {
|
|
58
|
+
const S = 31 - Math.clz32(u & -u);
|
|
59
|
+
let g = ge[S * ue + m], E = c[S];
|
|
60
|
+
if (g < T && (g = -1 - g, E += 1, E > i))
|
|
63
61
|
return !0;
|
|
64
|
-
if (
|
|
65
|
-
const
|
|
66
|
-
((
|
|
62
|
+
if (g === T) continue;
|
|
63
|
+
const v = 1 << g;
|
|
64
|
+
((d & v) === 0 || E > l[g]) && (l[g] = E), d |= v;
|
|
67
65
|
}
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
66
|
+
$(h) && (t.charCodeAt(n - 1) === I || t.charCodeAt(n - 1) === V && t.charCodeAt(n - 2) === I) && (d & 1 << A) === 0 && (l[A] = 0, d |= 1 << A);
|
|
67
|
+
const y = c;
|
|
68
|
+
c = l, l = y, s = d, n += 1;
|
|
71
69
|
}
|
|
72
70
|
return !1;
|
|
73
71
|
};
|
|
74
|
-
class
|
|
72
|
+
class O extends Error {
|
|
75
73
|
status;
|
|
76
74
|
constructor(i) {
|
|
77
75
|
super(`[markdown-explorer] the nesting guard stopped the parse: ${i}`), this.name = "ParseStop", this.status = i;
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
|
-
const
|
|
78
|
+
const Te = (t, i, c, l) => {
|
|
81
79
|
if (!Number.isSafeInteger(i) || i <= 0) throw new RangeError(`[markdown-explorer] the nesting guard's depth limit must be a positive safe integer; got ${String(i)}`);
|
|
82
|
-
if (!Number.isSafeInteger(
|
|
83
|
-
if (!Number.isSafeInteger(
|
|
84
|
-
if (
|
|
85
|
-
const
|
|
86
|
-
let n = null,
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
},
|
|
90
|
-
for (const
|
|
91
|
-
if (
|
|
92
|
-
},
|
|
93
|
-
const
|
|
94
|
-
return
|
|
95
|
-
},
|
|
96
|
-
const
|
|
97
|
-
if (
|
|
98
|
-
return
|
|
99
|
-
},
|
|
100
|
-
let
|
|
101
|
-
for (let
|
|
102
|
-
|
|
103
|
-
if (n !== null && n.height >
|
|
104
|
-
},
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
},
|
|
108
|
-
if (!
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
},
|
|
112
|
-
...
|
|
80
|
+
if (!Number.isSafeInteger(c) || c <= 0) throw new RangeError(`[markdown-explorer] the nesting guard's node budget must be a positive safe integer; got ${String(c)}`);
|
|
81
|
+
if (!Number.isSafeInteger(l) || l <= 0) throw new RangeError(`[markdown-explorer] the nesting guard's attribute character budget must be a positive safe integer; got ${String(l)}`);
|
|
82
|
+
if (me(t, P)) return { status: "too-many-attributes" };
|
|
83
|
+
const s = i + G, p = t.length + re;
|
|
84
|
+
let n = null, h = 0, m = 0, d = 0, y = 0;
|
|
85
|
+
const u = (e) => {
|
|
86
|
+
if (m += e, m > c) throw new O("too-many-nodes");
|
|
87
|
+
}, S = (e) => {
|
|
88
|
+
for (const r of e) y += r.name.length + r.value.length;
|
|
89
|
+
if (y > l) throw new O("too-many-attribute-characters");
|
|
90
|
+
}, g = (e, r, o, a) => {
|
|
91
|
+
const H = { node: e, above: null, levels: r, height: 0, keepsChildren: o, attributes: a, first: null, next: null, previous: null }, J = e;
|
|
92
|
+
return J[B] = H, H;
|
|
93
|
+
}, E = (e) => {
|
|
94
|
+
const o = e[B];
|
|
95
|
+
if (o === void 0) throw new Error("[markdown-explorer] the nesting guard was handed a node it did not create");
|
|
96
|
+
return o;
|
|
97
|
+
}, v = (e, r) => {
|
|
98
|
+
let o = r;
|
|
99
|
+
for (let a = e; a !== null && o > a.height; a = a.above)
|
|
100
|
+
a.height = o, o += a.levels;
|
|
101
|
+
if (n !== null && n.height > s) throw new O("too-deep");
|
|
102
|
+
}, x = (e) => {
|
|
103
|
+
const r = e.above;
|
|
104
|
+
r?.keepsChildren && (e.previous === null ? r.first = e.next : e.previous.next = e.next, e.next !== null && (e.next.previous = e.previous)), e.above = null, e.next = null, e.previous = null;
|
|
105
|
+
}, R = (e, r) => {
|
|
106
|
+
if (!w.isElementNode(r)) return;
|
|
107
|
+
const o = E(r), a = E(e);
|
|
108
|
+
x(o), o.above = a, a.keepsChildren && (o.next = a.first, a.first !== null && (a.first.previous = o), a.first = o), r.parentNode = e, v(a, o.height + o.levels);
|
|
109
|
+
}, X = {
|
|
110
|
+
...w,
|
|
113
111
|
createDocument: () => {
|
|
114
|
-
const
|
|
115
|
-
return n = e
|
|
112
|
+
const e = w.createDocument();
|
|
113
|
+
return n = g(e, 0, !1, 0), e;
|
|
116
114
|
},
|
|
117
115
|
createDocumentFragment: () => {
|
|
118
|
-
const
|
|
119
|
-
return e
|
|
116
|
+
const e = w.createDocumentFragment();
|
|
117
|
+
return g(e, 0, !1, 0), e;
|
|
120
118
|
},
|
|
121
|
-
createElement: (
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
return
|
|
119
|
+
createElement: (e, r, o) => {
|
|
120
|
+
if (h += 1, h > p) throw new O("too-many-elements");
|
|
121
|
+
u(1 + o.length), S(o);
|
|
122
|
+
const a = w.createElement(e, r, o);
|
|
123
|
+
return g(a, 1, !(r === ee.NS.HTML && ne.has(e)), o.length), a;
|
|
126
124
|
},
|
|
127
|
-
createCommentNode: (
|
|
128
|
-
if (
|
|
129
|
-
return
|
|
125
|
+
createCommentNode: (e) => {
|
|
126
|
+
if (d += 1, d > te) throw new O("too-many-comments");
|
|
127
|
+
return u(1), w.createCommentNode(e);
|
|
130
128
|
},
|
|
131
|
-
setTemplateContent: (
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
129
|
+
setTemplateContent: (e, r) => {
|
|
130
|
+
w.setTemplateContent(e, r);
|
|
131
|
+
const o = E(r);
|
|
132
|
+
o.above = E(e), v(o.above, o.height);
|
|
135
133
|
},
|
|
136
|
-
appendChild:
|
|
137
|
-
insertBefore: (
|
|
138
|
-
detachNode: (
|
|
139
|
-
|
|
134
|
+
appendChild: R,
|
|
135
|
+
insertBefore: (e, r) => R(e, r),
|
|
136
|
+
detachNode: (e) => {
|
|
137
|
+
w.isElementNode(e) && (x(E(e)), e.parentNode = null);
|
|
140
138
|
},
|
|
141
|
-
getFirstChild: (
|
|
142
|
-
const
|
|
143
|
-
if (!
|
|
144
|
-
return
|
|
139
|
+
getFirstChild: (e) => {
|
|
140
|
+
const r = E(e);
|
|
141
|
+
if (!r.keepsChildren) throw new Error("[markdown-explorer] the nesting guard was asked for the children of a node whose children it does not keep");
|
|
142
|
+
return r.first === null ? null : r.first.node;
|
|
145
143
|
},
|
|
146
144
|
getChildNodes: () => {
|
|
147
145
|
throw new Error("[markdown-explorer] the nesting guard keeps no child lists for source locations");
|
|
148
146
|
},
|
|
149
|
-
onItemPop: (
|
|
150
|
-
const
|
|
151
|
-
|
|
147
|
+
onItemPop: (e) => {
|
|
148
|
+
const r = E(e);
|
|
149
|
+
r.keepsChildren = !1, r.first = null;
|
|
152
150
|
},
|
|
153
151
|
insertText: () => {
|
|
154
152
|
},
|
|
155
153
|
insertTextBefore: () => {
|
|
156
154
|
},
|
|
157
|
-
adoptAttributes: (
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
155
|
+
adoptAttributes: (e, r) => {
|
|
156
|
+
u(r.length), S(r);
|
|
157
|
+
const o = E(e);
|
|
158
|
+
if (o.attributes += r.length, o.attributes > P) throw new O("too-many-attributes");
|
|
161
159
|
}
|
|
162
160
|
};
|
|
163
|
-
let
|
|
161
|
+
let k;
|
|
164
162
|
try {
|
|
165
|
-
|
|
166
|
-
} catch (
|
|
167
|
-
if (
|
|
168
|
-
throw
|
|
163
|
+
k = Z(t, { scriptingEnabled: !1, treeAdapter: X });
|
|
164
|
+
} catch (e) {
|
|
165
|
+
if (e instanceof O) return { status: e.status };
|
|
166
|
+
throw e;
|
|
169
167
|
}
|
|
170
|
-
return { status: "within", depth:
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
img: Object.freeze(["data-asset-src", "data-asset-exists"]),
|
|
181
|
-
section: Object.freeze(["data-footnotes"]),
|
|
182
|
-
iframe: Object.freeze(["allow", "allowfullscreen", "frameborder", "referrerpolicy"])
|
|
183
|
-
}), ze = [.../* @__PURE__ */ new Set([...Object.values(Z).flatMap((r) => r.filter((i) => i.startsWith("data-"))), P])], Be = /* @__PURE__ */ new Set(["src", "href", "xlink:href"]), Pe = /^data:/iu, ve = Object.freeze({
|
|
184
|
-
FORBID_TAGS: Ce,
|
|
185
|
-
FORBID_ATTR: Ie,
|
|
186
|
-
ADD_TAGS: ["iframe"],
|
|
187
|
-
ADD_ATTR: (r, i) => r === P || Z[i]?.includes(r) === !0,
|
|
188
|
-
ADD_URI_SAFE_ATTR: ze,
|
|
189
|
-
ALLOWED_URI_REGEXP: ye,
|
|
190
|
-
ALLOW_DATA_ATTR: !1
|
|
191
|
-
}), Fe = (r) => {
|
|
192
|
-
let i = null;
|
|
193
|
-
for (const u of r.split(";")) {
|
|
194
|
-
const f = u.indexOf(":");
|
|
195
|
-
if (f < 0 || u.slice(0, f).trim().toLowerCase() !== "text-align") continue;
|
|
196
|
-
const l = u.slice(f + 1).trim().toLowerCase();
|
|
197
|
-
De.has(l) && (i = l);
|
|
198
|
-
}
|
|
199
|
-
return i === null ? null : `text-align: ${i}`;
|
|
200
|
-
}, Ge = (r) => r.nodeType === Ue ? { kind: "text", text: r.nodeValue ?? "" } : r.nodeType === He || r.nodeType === xe ? { kind: "ignored" } : r.nodeType === U && r.nodeName.toLowerCase() === "a" ? { kind: "link", href: r.getAttribute("href") } : { kind: "element" }, je = (r) => {
|
|
201
|
-
const i = r.getAttribute("type");
|
|
202
|
-
return i !== null && i.trim().toLowerCase() === "checkbox" && r.hasAttribute("disabled");
|
|
203
|
-
}, Ve = (r, i, u) => {
|
|
204
|
-
if (S.isSupported !== !0) throw new Error("[markdown-explorer] the HTML sanitizer cannot run in this environment");
|
|
205
|
-
if (!Number.isSafeInteger(u) || u <= 0) throw new RangeError(`[markdown-explorer] the HTML sanitizer's depth limit must be a positive integer; got ${String(u)}`);
|
|
206
|
-
const f = Object.freeze([...r]);
|
|
207
|
-
let l = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new WeakMap();
|
|
208
|
-
const n = (a) => {
|
|
209
|
-
const e = a.parentNode === null ? void 0 : l.get(a.parentNode), o = e === void 0 ? 0 : e + 1;
|
|
210
|
-
if (l.set(a, o), a.nodeType === U && o > u) throw new q(u);
|
|
211
|
-
}, m = (a, e) => {
|
|
212
|
-
if (a.nodeType !== U) return;
|
|
213
|
-
const o = a;
|
|
214
|
-
(e.tagName === "input" && !je(o) || e.tagName === "iframe" && oe(o.getAttribute("src")?.trim(), f) === null) && o.parentNode?.removeChild(o);
|
|
215
|
-
}, g = (a, e) => {
|
|
216
|
-
const o = a.nodeName.toLowerCase();
|
|
217
|
-
if (e.attrName === "style") {
|
|
218
|
-
const E = Fe(e.attrValue);
|
|
219
|
-
E === null ? e.keepAttr = !1 : e.attrValue = E;
|
|
220
|
-
} else if (e.attrName === "allow" && o === "iframe") {
|
|
221
|
-
const E = se(e.attrValue);
|
|
222
|
-
E === null ? e.keepAttr = !1 : e.attrValue = E;
|
|
223
|
-
} else if (e.attrName === "referrerpolicy" && o === "iframe") {
|
|
224
|
-
const E = e.attrValue.trim().toLowerCase();
|
|
225
|
-
ae.has(E) ? e.attrValue = E : e.keepAttr = !1;
|
|
226
|
-
} else e.attrName === H && o === "p" ? T.set(a, a.getAttribute(H)) : Be.has(e.attrName) && Pe.test(e.attrValue) || e.attrName === P && le(e.attrValue) === null ? e.keepAttr = !1 : e.attrName === "id" && Me.has(o) && (e.forceKeepAttr = !0);
|
|
227
|
-
}, h = (a) => {
|
|
228
|
-
const e = a.getAttribute("data-asset-src");
|
|
229
|
-
e !== null && (a.getAttribute("data-asset-exists") !== "false" && ce(e) ? a.setAttribute("src", ue(i, e, null)) : a.removeAttribute("src"));
|
|
230
|
-
}, R = (a) => {
|
|
231
|
-
const e = a.parentNode;
|
|
232
|
-
if (e === null) return;
|
|
233
|
-
const o = T.get(e);
|
|
234
|
-
o != null && ie(o, [...e.childNodes].map(Ge)) !== null && e.setAttribute(H, o);
|
|
235
|
-
}, p = (a) => {
|
|
236
|
-
if (a.nodeType !== U) return;
|
|
237
|
-
const e = a, o = e.nodeName.toLowerCase();
|
|
238
|
-
o === "img" ? h(e) : o === "a" && R(e);
|
|
239
|
-
const E = e.getAttribute("target");
|
|
240
|
-
if (E === null || E.trim().toLowerCase() === "_self") return;
|
|
241
|
-
const y = e.getAttribute("rel"), C = new Set(y === null ? [] : y.split(/\s+/u).filter((x) => x !== ""));
|
|
242
|
-
C.add("noopener"), C.add("noreferrer"), e.setAttribute("rel", [...C].join(" "));
|
|
243
|
-
};
|
|
244
|
-
return (a) => {
|
|
245
|
-
l = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new WeakMap(), S.addHook("beforeSanitizeElements", n), S.addHook("uponSanitizeElement", m), S.addHook("uponSanitizeAttribute", g), S.addHook("afterSanitizeAttributes", p);
|
|
246
|
-
try {
|
|
247
|
-
return S.sanitize(a, ve);
|
|
248
|
-
} finally {
|
|
249
|
-
S.removeHook("beforeSanitizeElements", n), S.removeHook("uponSanitizeElement", m), S.removeHook("uponSanitizeAttribute", g), S.removeHook("afterSanitizeAttributes", p);
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
}, We = (r) => {
|
|
253
|
-
if (r === null || typeof r != "object") return !1;
|
|
254
|
-
const { id: i, input: u } = r;
|
|
255
|
-
if (typeof i != "number" || u === null || typeof u != "object") return !1;
|
|
256
|
-
const { html: f, iframeHosts: l, dataPath: T, maxNodes: n, maxAttributeChars: m, maxSanitizedChars: g } = u;
|
|
257
|
-
return typeof f == "string" && Array.isArray(l) && l.every((h) => typeof h == "string") && typeof T == "string" && T !== "" && [n, m, g].every((h) => Number.isSafeInteger(h) && h > 0);
|
|
258
|
-
}, Qe = () => {
|
|
259
|
-
const r = te;
|
|
260
|
-
if (r === null) throw new Error("[markdown-explorer] the sanitizer worker must run in a worker thread");
|
|
168
|
+
return { status: "within", depth: E(k).height - G, elements: h, nodes: m };
|
|
169
|
+
}, Ae = (t) => {
|
|
170
|
+
if (t === null || typeof t != "object") return !1;
|
|
171
|
+
const { id: i, input: c } = t;
|
|
172
|
+
if (typeof i != "number" || c === null || typeof c != "object") return !1;
|
|
173
|
+
const { html: l, iframeHosts: s, dataPath: p, maxNodes: n, maxAttributeChars: h, maxSanitizedChars: m } = c;
|
|
174
|
+
return typeof l == "string" && Array.isArray(s) && s.every((d) => typeof d == "string") && typeof p == "string" && p !== "" && [n, h, m].every((d) => Number.isSafeInteger(d) && d > 0);
|
|
175
|
+
}, Se = () => {
|
|
176
|
+
const t = W;
|
|
177
|
+
if (t === null) throw new Error("[markdown-explorer] the sanitizer worker must run in a worker thread");
|
|
261
178
|
const i = /* @__PURE__ */ new Map();
|
|
262
|
-
|
|
263
|
-
if (!
|
|
264
|
-
const { id:
|
|
265
|
-
let
|
|
179
|
+
t.on("message", (c) => {
|
|
180
|
+
if (!Ae(c)) throw new TypeError("[markdown-explorer] the sanitizer worker received a message that is not a job");
|
|
181
|
+
const { id: l, input: s } = c;
|
|
182
|
+
let p;
|
|
266
183
|
try {
|
|
267
|
-
if (
|
|
268
|
-
|
|
184
|
+
if (Te(s.html, D, s.maxNodes, s.maxAttributeChars).status !== "within") {
|
|
185
|
+
t.postMessage({ id: l, output: { status: "too-large" } });
|
|
269
186
|
return;
|
|
270
187
|
}
|
|
271
|
-
const n = JSON.stringify([
|
|
272
|
-
let
|
|
273
|
-
|
|
274
|
-
const
|
|
275
|
-
|
|
188
|
+
const n = JSON.stringify([s.iframeHosts, s.dataPath]);
|
|
189
|
+
let h = i.get(n);
|
|
190
|
+
h === void 0 && (h = K(q, s.iframeHosts, s.dataPath, D), i.set(n, h));
|
|
191
|
+
const m = h(s.html);
|
|
192
|
+
p = m.length > s.maxSanitizedChars ? { status: "too-large" } : { status: "sanitized", html: m };
|
|
276
193
|
} catch (n) {
|
|
277
|
-
|
|
194
|
+
p = n instanceof Y ? { status: "too-large" } : { status: "error", message: n instanceof Error ? `${n.name}: ${n.message}` : String(n) };
|
|
278
195
|
}
|
|
279
|
-
|
|
280
|
-
}),
|
|
196
|
+
t.postMessage({ id: l, output: p });
|
|
197
|
+
}), t.postMessage({ ready: !0 });
|
|
281
198
|
};
|
|
282
|
-
|
|
199
|
+
Se();
|