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