@aiquants/markdown-explorer 0.18.0 → 0.20.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 +55 -1
- package/README.md +18 -9
- package/dist/EditSurface-D1yklbWu.js +833 -0
- package/dist/EditSurface-GxmyUeGE.cjs +3 -0
- package/dist/{ExplorerSplit-qAKZsLZa.js → ExplorerSplit-BAYa3WO3.js} +2 -2
- package/dist/ExplorerSplit-DkE46pS0.cjs +1 -0
- package/dist/{MultiLayout-rsmtFma5.js → MultiLayout-BkhnkQs5.js} +2 -2
- package/dist/{MultiLayout-Bc6RYc3U.cjs → MultiLayout-DsxYURra.cjs} +1 -1
- package/dist/{NativeScrollBar-DqTkrnPZ.cjs → NativeScrollBar-B57yWQVG.cjs} +1 -1
- package/dist/{NativeScrollBar-Dq3YeUVY.js → NativeScrollBar-CcNqDlO6.js} +1 -1
- package/dist/{TreeLayout-BPa7NdeT.js → TreeLayout-Cf2PzZEI.js} +2 -2
- package/dist/{TreeLayout-DXoEAcpD.cjs → TreeLayout-DCGqVwt9.cjs} +1 -1
- package/dist/core/labels.d.cts +26 -0
- package/dist/core/labels.d.ts +26 -0
- package/dist/index-Bdve5EFS.cjs +13 -0
- package/dist/{index-25s_q0vD.js → index-DiLkl4dC.js} +1323 -1238
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{merge-B9jrWxMa.js → merge-BIXNcrea.js} +1 -1
- package/dist/{merge-DuTAponF.cjs → merge-DSfJceoQ.cjs} +1 -1
- package/dist/sanitizePolicy-BWQtWhsL.js +98 -0
- package/dist/sanitizePolicy-gEXeavb-.cjs +1 -0
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +1 -1
- package/docs/behavior/localization.md +5 -1
- package/docs/behavior/security.md +1 -1
- package/package.json +9 -7
- package/dist/EditSurface-B2bzY1b_.js +0 -786
- package/dist/EditSurface-BRuIjA9L.cjs +0 -2
- package/dist/ExplorerSplit-BE1VJuok.cjs +0 -1
- package/dist/index-W3iAjkLb.cjs +0 -13
- package/dist/sanitizePolicy-DlrakwA4.js +0 -96
- package/dist/sanitizePolicy-DrIMuYCb.cjs +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./index-Bdve5EFS.cjs"),e=require("./storage-DM0EvkVf.cjs"),E=require("./location-BVEN_Ihk.cjs"),_=require("./dataRoute-BONacTPi.cjs");exports.DEFAULT_MARKDOWN_EXPLORER_LOCALE=L.DEFAULT_MARKDOWN_EXPLORER_LOCALE;exports.EXPLORER_THEMES=L.EXPLORER_THEMES;exports.MARKDOWN_EXPLORER_LABEL_CATALOGS=L.MARKDOWN_EXPLORER_LABEL_CATALOGS;exports.MARKDOWN_EXPLORER_LABEL_KEYS=L.MARKDOWN_EXPLORER_LABEL_KEYS;exports.MARKDOWN_EXPLORER_LABEL_TEMPLATES=L.MARKDOWN_EXPLORER_LABEL_TEMPLATES;exports.MARKDOWN_EXPLORER_LOCALES=L.MARKDOWN_EXPLORER_LOCALES;exports.MarkdownExplorer=L.MarkdownExplorer;exports.resolveMarkdownExplorerLabels=L.resolveMarkdownExplorerLabels;exports.shouldRevalidateExplorer=L.shouldRevalidateExplorer;exports.clearExplorerStorage=e.clearExplorerStorage;exports.COLUMN_MIN_MEASURE=E.COLUMN_MIN_MEASURE;exports.DEFAULT_TREE_SETTINGS=E.DEFAULT_TREE_SETTINGS;exports.DEFAULT_VIEW_SLUGS=E.DEFAULT_VIEW_SLUGS;exports.EXPAND_ALL_DEPTH_LIMITS=E.EXPAND_ALL_DEPTH_LIMITS;exports.EXPAND_ALL_FOLDER_LIMITS=E.EXPAND_ALL_FOLDER_LIMITS;exports.EXPLORER_DEFAULT_PERCENT=E.EXPLORER_DEFAULT_PERCENT;exports.EXPLORER_MAX_PERCENT=E.EXPLORER_MAX_PERCENT;exports.EXPLORER_MIN_REM=E.EXPLORER_MIN_REM;exports.EXPLORER_MULTI_DEFAULT_PERCENT=E.EXPLORER_MULTI_DEFAULT_PERCENT;exports.GOLDEN_RATIO=E.GOLDEN_RATIO;exports.MULTI_VIEW_COLUMN_LIMITS=E.MULTI_VIEW_COLUMN_LIMITS;exports.MULTI_VIEW_PANEL_LIMITS=E.MULTI_VIEW_PANEL_LIMITS;exports.REVEAL_DOCUMENT_DEPTH_LIMITS=E.REVEAL_DOCUMENT_DEPTH_LIMITS;exports.defineExplorerConfig=E.defineExplorerConfig;exports.explorerHref=E.explorerHref;exports.isExplorerSourceId=E.isExplorerSourceId;exports.resolveExplorerLocation=E.resolveExplorerLocation;exports.withExplorerSources=E.withExplorerSources;exports.DEFAULT_DENIED_PATH_SEGMENTS=_.DEFAULT_DENIED_PATH_SEGMENTS;exports.EXPLORER_EDIT_TOKEN_MAX_LENGTH=_.EXPLORER_EDIT_TOKEN_MAX_LENGTH;exports.EXPLORER_FAILURE_REASONS=_.EXPLORER_FAILURE_REASONS;exports.EXPLORER_MAX_HEADINGS=_.EXPLORER_MAX_HEADINGS;exports.MAX_DOCUMENT_PATH_LENGTH=_.MAX_DOCUMENT_PATH_LENGTH;exports.failureDocument=_.failureDocument;exports.failureOf=_.failureOf;exports.isAcceptableDocumentPath=_.isAcceptableDocumentPath;exports.isDeniedPath=_.isDeniedPath;exports.isExplorerChildrenResult=_.isExplorerChildrenResult;exports.isExplorerFailureCode=_.isExplorerFailureCode;exports.isExplorerFailureReason=_.isExplorerFailureReason;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { W as a, X as L, Y as s, Z as e, _ as r, $ as R, a0 as A, a1 as T, a2 as o } from "./index-
|
|
1
|
+
import { W as a, X as L, Y as s, Z as e, _ as r, $ as R, a0 as A, a1 as T, a2 as o } from "./index-DiLkl4dC.js";
|
|
2
2
|
import { c as O } from "./storage-CmGHg7OA.js";
|
|
3
3
|
import { R as N, T as P, U as l, V as I, W as S, x as X, u as i, X as p, y as x, H as U, Y as t, Z as C, _ as f, $ as u, e as W, i as c, g as n, w as F } from "./location-B-m9scLf.js";
|
|
4
4
|
import { D as d, V as G, W as K, E as m, M as V, z as h, f as w, i as b, C as g, L as v, c as B, b as Y } from "./dataRoute-CObbjNxG.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { diff3Merge as d } from "node-diff3";
|
|
2
|
-
import { C, a as R, b as u } from "./index-
|
|
2
|
+
import { C, a as R, b as u } from "./index-DiLkl4dC.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 };
|
|
@@ -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-Bdve5EFS.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(`
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { CODE_META_ATTRIBUTE as w } from "@aiquants/markdown/code-blocks";
|
|
2
|
+
import { allowedFrameUrlOf as O, reduceFrameFeatures as L, EMBED_FRAME_REFERRER_POLICIES as D, EMBED_LINK_ATTRIBUTE as T, placeholderLinkOf as I } from "@aiquants/markdown/embeds";
|
|
3
|
+
import { SOURCE_LINES_ATTRIBUTE as E, parseSourceLines as z } from "@aiquants/markdown/source-lines";
|
|
4
|
+
import { i as M, e as x } from "./dataRoute-CObbjNxG.js";
|
|
5
|
+
const ee = 512;
|
|
6
|
+
class H extends RangeError {
|
|
7
|
+
constructor(o) {
|
|
8
|
+
super(`[markdown-explorer] the HTML nests deeper than ${String(o)} levels`), this.name = "HtmlNestingLimitError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const C = ["script", "style", "noscript", "template", "form", "button", "textarea", "select", "option", "object", "embed", "base", "meta", "link", "frame", "frameset"], U = ["srcdoc", "formaction"], j = /^(?:(?:https?|mailto|tel):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/iu, B = /* @__PURE__ */ new Set(["left", "right", "center", "justify", "start", "end"]), F = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]), u = 1, G = 3, y = 7, V = 8, S = Object.freeze({
|
|
12
|
+
a: Object.freeze(["target", "data-link-kind", "data-doc-path", "data-doc-exists", "data-footnote-ref", "data-footnote-backref"]),
|
|
13
|
+
area: Object.freeze(["target"]),
|
|
14
|
+
img: Object.freeze(["data-asset-src", "data-asset-exists"]),
|
|
15
|
+
section: Object.freeze(["data-footnotes"]),
|
|
16
|
+
code: Object.freeze([w]),
|
|
17
|
+
iframe: Object.freeze(["allow", "allowfullscreen", "frameborder", "referrerpolicy"])
|
|
18
|
+
}), P = [.../* @__PURE__ */ new Set([...Object.values(S).flatMap((t) => t.filter((o) => o.startsWith("data-"))), E])], W = /* @__PURE__ */ new Set(["src", "href", "xlink:href"]), X = /^data:/iu, $ = Object.freeze({
|
|
19
|
+
FORBID_TAGS: C,
|
|
20
|
+
FORBID_ATTR: U,
|
|
21
|
+
ADD_TAGS: ["iframe"],
|
|
22
|
+
ADD_ATTR: (t, o) => t === E || S[o]?.includes(t) === !0,
|
|
23
|
+
ADD_URI_SAFE_ATTR: P,
|
|
24
|
+
ALLOWED_URI_REGEXP: j,
|
|
25
|
+
ALLOW_DATA_ATTR: !1
|
|
26
|
+
}), K = (t) => {
|
|
27
|
+
let o = null;
|
|
28
|
+
for (const l of t.split(";")) {
|
|
29
|
+
const n = l.indexOf(":");
|
|
30
|
+
if (n < 0 || l.slice(0, n).trim().toLowerCase() !== "text-align") continue;
|
|
31
|
+
const f = l.slice(n + 1).trim().toLowerCase();
|
|
32
|
+
B.has(f) && (o = f);
|
|
33
|
+
}
|
|
34
|
+
return o === null ? null : `text-align: ${o}`;
|
|
35
|
+
}, Y = (t) => t.nodeType === G ? { kind: "text", text: t.nodeValue ?? "" } : t.nodeType === V || t.nodeType === y ? { kind: "ignored" } : t.nodeType === u && t.nodeName.toLowerCase() === "a" ? { kind: "link", href: t.getAttribute("href") } : { kind: "element" }, q = (t) => {
|
|
36
|
+
const o = t.getAttribute("type");
|
|
37
|
+
return o !== null && o.trim().toLowerCase() === "checkbox" && t.hasAttribute("disabled");
|
|
38
|
+
}, te = (t, o, l, n) => {
|
|
39
|
+
if (t.isSupported !== !0) throw new Error("[markdown-explorer] the HTML sanitizer cannot run in this environment");
|
|
40
|
+
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)}`);
|
|
41
|
+
const f = Object.freeze([...o]);
|
|
42
|
+
let m = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), d;
|
|
43
|
+
const p = (r) => {
|
|
44
|
+
const e = r.parentNode === null ? void 0 : m.get(r.parentNode), a = e === void 0 ? 0 : e + 1;
|
|
45
|
+
if (m.set(r, a), r.nodeType === u && a > n) throw new H(n);
|
|
46
|
+
}, b = (r, e) => {
|
|
47
|
+
if (r.nodeType !== u) return;
|
|
48
|
+
const a = r;
|
|
49
|
+
(e.tagName === "input" && !q(a) || e.tagName === "iframe" && O(a.getAttribute("src")?.trim(), f) === null) && a.parentNode?.removeChild(a);
|
|
50
|
+
}, _ = (r, e) => {
|
|
51
|
+
const a = r.nodeName.toLowerCase();
|
|
52
|
+
if (e.attrName === "style") {
|
|
53
|
+
const s = K(e.attrValue);
|
|
54
|
+
s === null ? e.keepAttr = !1 : e.attrValue = s;
|
|
55
|
+
} else if (e.attrName === "allow" && a === "iframe") {
|
|
56
|
+
const s = L(e.attrValue);
|
|
57
|
+
s === null ? e.keepAttr = !1 : e.attrValue = s;
|
|
58
|
+
} else if (e.attrName === "referrerpolicy" && a === "iframe") {
|
|
59
|
+
const s = e.attrValue.trim().toLowerCase();
|
|
60
|
+
D.has(s) ? e.attrValue = s : e.keepAttr = !1;
|
|
61
|
+
} else e.attrName === T && a === "p" ? A.set(r, r.getAttribute(T)) : W.has(e.attrName) && X.test(e.attrValue) || e.attrName === E && z(e.attrValue) === null ? e.keepAttr = !1 : e.attrName === "id" && F.has(a) && (e.forceKeepAttr = !0);
|
|
62
|
+
}, k = (r) => {
|
|
63
|
+
const e = r.getAttribute("data-asset-src");
|
|
64
|
+
e !== null && (r.getAttribute("data-asset-exists") !== "false" && M(e) ? r.setAttribute("src", x(l, e, null)) : r.removeAttribute("src"));
|
|
65
|
+
}, h = (r, e, a, s) => {
|
|
66
|
+
if (d === void 0) return;
|
|
67
|
+
const c = r.getAttribute(a);
|
|
68
|
+
if (c === null) return;
|
|
69
|
+
const i = d({ kind: e, path: c });
|
|
70
|
+
i !== void 0 && r.setAttribute(s, String(i));
|
|
71
|
+
}, g = (r) => {
|
|
72
|
+
const e = r.parentNode;
|
|
73
|
+
if (e === null) return;
|
|
74
|
+
const a = A.get(e);
|
|
75
|
+
a != null && I(a, [...e.childNodes].map(Y)) !== null && e.setAttribute(T, a);
|
|
76
|
+
}, N = (r) => {
|
|
77
|
+
if (r.nodeType !== u) return;
|
|
78
|
+
const e = r, a = e.nodeName.toLowerCase();
|
|
79
|
+
a === "img" ? (h(e, "asset", "data-asset-src", "data-asset-exists"), k(e)) : a === "a" && (h(e, "doc", "data-doc-path", "data-doc-exists"), g(e));
|
|
80
|
+
const s = e.getAttribute("target");
|
|
81
|
+
if (s === null || s.trim().toLowerCase() === "_self") return;
|
|
82
|
+
const c = e.getAttribute("rel"), i = new Set(c === null ? [] : c.split(/\s+/u).filter((R) => R !== ""));
|
|
83
|
+
i.add("noopener"), i.add("noreferrer"), e.setAttribute("rel", [...i].join(" "));
|
|
84
|
+
};
|
|
85
|
+
return (r, e) => {
|
|
86
|
+
m = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), d = e, t.addHook("beforeSanitizeElements", p), t.addHook("uponSanitizeElement", b), t.addHook("uponSanitizeAttribute", _), t.addHook("afterSanitizeAttributes", N);
|
|
87
|
+
try {
|
|
88
|
+
return t.sanitize(r, $);
|
|
89
|
+
} finally {
|
|
90
|
+
t.removeHook("beforeSanitizeElements", p), t.removeHook("uponSanitizeElement", b), t.removeHook("uponSanitizeAttribute", _), t.removeHook("afterSanitizeAttributes", N), d = void 0;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
export {
|
|
95
|
+
H,
|
|
96
|
+
ee as M,
|
|
97
|
+
te as c
|
|
98
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const O=require("@aiquants/markdown/code-blocks"),i=require("@aiquants/markdown/embeds"),E=require("@aiquants/markdown/source-lines"),R=require("./dataRoute-BONacTPi.cjs"),w=512;class h extends RangeError{constructor(s){super(`[markdown-explorer] the HTML nests deeper than ${String(s)} levels`),this.name="HtmlNestingLimitError"}}const D=["script","style","noscript","template","form","button","textarea","select","option","object","embed","base","meta","link","frame","frameset"],z=["srcdoc","formaction"],M=/^(?:(?:https?|mailto|tel):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/iu,B=new Set(["left","right","center","justify","start","end"]),H=new Set(["h1","h2","h3","h4","h5","h6"]),T=1,U=3,C=7,x=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"]),code:Object.freeze([O.CODE_META_ATTRIBUTE]),iframe:Object.freeze(["allow","allowfullscreen","frameborder","referrerpolicy"])}),j=[...new Set([...Object.values(k).flatMap(t=>t.filter(s=>s.startsWith("data-"))),E.SOURCE_LINES_ATTRIBUTE])],F=new Set(["src","href","xlink:href"]),G=/^data:/iu,y=Object.freeze({FORBID_TAGS:D,FORBID_ATTR:z,ADD_TAGS:["iframe"],ADD_ATTR:(t,s)=>t===E.SOURCE_LINES_ATTRIBUTE||k[s]?.includes(t)===!0,ADD_URI_SAFE_ATTR:j,ALLOWED_URI_REGEXP:M,ALLOW_DATA_ATTR:!1}),V=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();B.has(d)&&(s=d)}return s===null?null:`text-align: ${s}`},P=t=>t.nodeType===U?{kind:"text",text:t.nodeValue??""}:t.nodeType===x||t.nodeType===C?{kind:"ignored"}:t.nodeType===T&&t.nodeName.toLowerCase()==="a"?{kind:"link",href:t.getAttribute("href")}:{kind:"element"},W=t=>{const s=t.getAttribute("type");return s!==null&&s.trim().toLowerCase()==="checkbox"&&t.hasAttribute("disabled")},X=(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 A=new WeakMap,m=new WeakMap,f;const _=r=>{const e=r.parentNode===null?void 0:A.get(r.parentNode),a=e===void 0?0:e+1;if(A.set(r,a),r.nodeType===T&&a>n)throw new h(n)},p=(r,e)=>{if(r.nodeType!==T)return;const a=r;(e.tagName==="input"&&!W(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=V(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)):F.has(e.attrName)&&G.test(e.attrValue)||e.attrName===E.SOURCE_LINES_ATTRIBUTE&&E.parseSourceLines(e.attrValue)===null?e.keepAttr=!1:e.attrName==="id"&&H.has(a)&&(e.forceKeepAttr=!0)},g=r=>{const e=r.getAttribute("data-asset-src");e!==null&&(r.getAttribute("data-asset-exists")!=="false"&&R.isAcceptableDocumentPath(e)?r.setAttribute("src",R.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))},I=r=>{const e=r.parentNode;if(e===null)return;const a=m.get(e);a!=null&&i.placeholderLinkOf(a,[...e.childNodes].map(P))!==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"),I(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(L=>L!==""));l.add("noopener"),l.add("noreferrer"),e.setAttribute("rel",[...l].join(" "))};return(r,e)=>{A=new WeakMap,m=new WeakMap,f=e,t.addHook("beforeSanitizeElements",_),t.addHook("uponSanitizeElement",p),t.addHook("uponSanitizeAttribute",N),t.addHook("afterSanitizeAttributes",b);try{return t.sanitize(r,y)}finally{t.removeHook("beforeSanitizeElements",_),t.removeHook("uponSanitizeElement",p),t.removeHook("uponSanitizeAttribute",N),t.removeHook("afterSanitizeAttributes",b),f=void 0}}};exports.HtmlNestingLimitError=h;exports.MAX_HTML_NESTING_DEPTH=w;exports.createHtmlSanitizer=X;
|
package/dist/sanitizeWorker.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const J=require("node:worker_threads"),W=require("isomorphic-dompurify"),M=require("./sanitizePolicy-
|
|
1
|
+
"use strict";const J=require("node:worker_threads"),W=require("isomorphic-dompurify"),M=require("./sanitizePolicy-gEXeavb-.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,6 +1,6 @@
|
|
|
1
1
|
import { parentPort as W } from "node:worker_threads";
|
|
2
2
|
import q from "isomorphic-dompurify";
|
|
3
|
-
import { M as D, c as K, H as Y } from "./sanitizePolicy-
|
|
3
|
+
import { M as D, c as K, H as Y } from "./sanitizePolicy-BWQtWhsL.js";
|
|
4
4
|
import { defaultTreeAdapter as w, parse as Z, html as ee } from "parse5";
|
|
5
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
6
|
switch (t) {
|
|
@@ -9,7 +9,10 @@ This page is part of the host-facing contract of `@aiquants/markdown-explorer`;
|
|
|
9
9
|
- The explorer passes its document-viewer strings to `@aiquants/markdown`, which names every control and status text of the viewer with them, so the viewer follows the same language:
|
|
10
10
|
its status texts (`viewerLoading`, `viewerErrorPrefix`, `viewerErrorTitle`, `viewerMissingImage`), its toolbar's buttons (`viewerSelectAlign`, `viewerSelectStyle`, `viewerOpenToc`), the alignment and style menus (`viewerAlignTitle`, `viewerAlignLeft`, `viewerAlignCenter`, `viewerAlignRight`, `viewerPinAlign`, `viewerUnpinAlign`, `viewerStyleTitle`, `viewerPinStyle`, `viewerUnpinStyle`), the table of contents (`viewerTocTitle`, which also names its navigation, `viewerPinToc`, `viewerUnpinToc`)
|
|
11
11
|
and every Mermaid diagram's controls (`viewerMermaidInteractionMode` for the mouse-interaction menu and its button, `viewerMermaidModeNone`, `viewerMermaidModeZoom`, `viewerMermaidModePan`, `viewerMermaidModePanShift`, `viewerMermaidModeBoth`, `viewerMermaidModeBothShift` for its modes, `viewerMermaidInteractionModeTouch` for the same menu and button under a coarse pointer, `viewerMermaidModeNoneTouch`, `viewerMermaidModeZoomTouch`, `viewerMermaidModePanTouch`, `viewerMermaidModeBothTouch` for its touch items, `viewerMermaidZoomIn`, `viewerMermaidZoomOut`, `viewerMermaidResetView`,
|
|
12
|
-
`viewerMermaidPanUp`, `viewerMermaidPanDown`, `viewerMermaidPanLeft`, `viewerMermaidPanRight` for the buttons that move the view while the drawing overflows its frame, `viewerMermaidRetry`, and `viewerMermaidDiagram`, the name of the diagram's focusable frame),
|
|
12
|
+
`viewerMermaidPanUp`, `viewerMermaidPanDown`, `viewerMermaidPanLeft`, `viewerMermaidPanRight` for the buttons that move the view while the drawing overflows its frame, `viewerMermaidRetry`, and `viewerMermaidDiagram`, the name of the diagram's focusable frame),
|
|
13
|
+
every ```spreadsheets table (`viewerSpreadsheetTable` and `viewerSpreadsheetFullscreenDialog` for the table's name in the document and full screen, `viewerSpreadsheetZoomIn`, `viewerSpreadsheetZoomOut`, `viewerSpreadsheetResetZoom`, `viewerSpreadsheetHighlight`, `viewerSpreadsheetCopyAll`, `viewerSpreadsheetSaveTsv`, `viewerSpreadsheetSaveMenu`, `viewerSpreadsheetSaveTsvWithBom`, `viewerSpreadsheetFullscreen` and `viewerSpreadsheetExitFullscreen` for its toolbar and save menu, `viewerSpreadsheetSize` for its size, `viewerSpreadsheetFileName` for the saved file,
|
|
14
|
+
`viewerSpreadsheetCopied`, `viewerSpreadsheetCopyFailed`, `viewerSpreadsheetReadOnly`, `viewerSpreadsheetFormatRefused`, `viewerSpreadsheetFenceRefused`, `viewerSpreadsheetEditConflict`, `viewerSpreadsheetOptionsError` and `viewerSpreadsheetLoadFailed` for its notices,
|
|
15
|
+
`viewerSpreadsheetCellAnnouncement`, `viewerSpreadsheetEmptyCell` and `viewerSpreadsheetSelectionAnnouncement` for what it announces, and `viewerSpreadsheetRetry`; the grid takes `locale` as its own locale, which picks the language of its own catalog, its data-validation messages and its scroll bar), and the titles of embedded frames (`viewerEmbeddedVideo` and `viewerEmbeddedPost` after a provider's name, as in "YouTube: embedded video", and `viewerEmbeddedFrame` before the host of an iframe written in a document without a title).
|
|
13
16
|
A label the viewer receives carries no `lang` of its own, so it is read in the page's language. Where the viewer's own built-in label is in a catalog's language, the catalog repeats it word for word (the English catalog the viewer's English labels, such as `Display Style` and `Zoom In`; the Japanese catalog its Japanese ones, such as `目次を開く`), writing a full-width form in half-width (`拡大縮小+移動 (左ドラッグ)` for the viewer's `拡大縮小+移動 (左ドラッグ)`).
|
|
14
17
|
- The explorer passes `treeEntryKindDirectory` and `treeEntryKindFile` (the kind words in the rows' accessible names) and `treeScrollUp`, `treeScrollDown`, `treeScrollToTop` and `treeScrollToBottom` (the tree's scroll bar) to `@aiquants/directory-tree`.
|
|
15
18
|
- The explorer passes every string the multi view's drag-and-drop layout shows to `@aiquants/drag-drop-panels`: the panel headers' buttons (`panelMove`, `panelSwitchToCustomDrag`, `panelSwitchToNormalDrag`, `panelHide`, `panelMaximize`, `panelRestore`, `panelClose`), the items of their move menus (`panelMovePreviousColumn`, `panelMoveNextColumn`, `panelMoveUp`, `panelMoveDown`) and the custom drag mode's badge (`panelCustomDragBadge`),
|
|
@@ -44,6 +47,7 @@ const HANDBOOK_LABELS = {
|
|
|
44
47
|
the path's last segment and the failure's title — the text of the matching `failure…Title` label, not the reason's code), `imageZoomLevel(percent)`, `treeRefreshFailed(reason)`, `documentRefreshed(name)`, `documentRefreshFailed(reason)`, `refreshDocumentNamed(name)` (a multi-view panel's icon-only Refresh document: its accessible name and tooltip, `name` being the panel title),
|
|
45
48
|
`showMarkupNamed(name)` (a multi-view panel's icon-only Source toggle: its accessible name and tooltip, `name` being the panel title), `panelLimit(max)`, `panelOpened(name)`, `panelClosed(name)`, `panelAlreadyOpen(name)`, `panelHidden(name)`, `panelShown(name)`, `panelMaximized(name)`, `panelRestored(name)` — so each language can place the value where its grammar needs it.
|
|
46
49
|
- The labels `@aiquants/drag-drop-panels` fills itself are templates instead, strings whose `{name}` placeholders mark where each value goes: `panelMoved` (`{title}` the panel's name, `{column}` its visible column, `{position}` its place among that column's shown panels), `panelMoveUnavailable` (`{title}`, and `{move}` the name of the move, one of the `panelMove…` labels), `panelDragStarted` and `panelDragCancelled` (`{title}`) and `multiColumnRegion` (`{column}`); columns and positions count from 1.
|
|
50
|
+
So are the table labels `@aiquants/markdown` fills: `viewerSpreadsheetSize` (`{rows}` and `{cols}`, the table's rows and columns), `viewerSpreadsheetCopyFailed` (`{reason}`, why the copy failed), `viewerSpreadsheetCellAnnouncement` (`{cell}` the cell's A1 name, `{value}` its value or `viewerSpreadsheetEmptyCell`), `viewerSpreadsheetSelectionAnnouncement` (`{range}`, the selection's A1 range), and `viewerSpreadsheetOptionsError` and `viewerSpreadsheetLoadFailed` (`{message}`, what is wrong).
|
|
47
51
|
`MARKDOWN_EXPLORER_LABEL_TEMPLATES` lists each template's placeholders, and braces in every other label are literal text.
|
|
48
52
|
- `labels` must be a plain object. An unknown key throws a `RangeError` that lists the valid keys, a value of the wrong type (a string where a function is expected, or the reverse) throws a `TypeError`, and a blank string throws a `RangeError`, because a blank name is neither shown nor announced. A template that uses a placeholder its key does not offer (`{name}` for `{title}`, say) throws a `RangeError` naming the placeholders it accepts, because a placeholder that is never filled would be read out as it is. A key set to `undefined` keeps the catalog's string.
|
|
49
53
|
- The overrides are compared by value, key by key: writing `labels={{ … }}` inline does not re-render the explorer on every render of the host, but a function created inline is a new value each time — hoist it, or memoize the object.
|
|
@@ -42,7 +42,7 @@ Markdown HTML returned by a source is sanitized on the server with DOMPurify, in
|
|
|
42
42
|
- `target` survives only on `a` and `area`, and a link with any `target` other than `_self` gets `rel="noopener noreferrer"`;
|
|
43
43
|
- `id` attributes that would clobber `document` or form properties (`cookie`, `forms`, `location`, …) are removed — except on headings, which the table of contents needs and which cannot clobber `document`;
|
|
44
44
|
- the markup converters write for GitHub alerts and Zenn's message and details containers survives as written, through DOMPurify's own allow-lists: `div`, `p`, `aside`, `span`, `details` and `summary` with their `class` (and `aria-hidden` on a message's symbol), and an alert's inline SVG icon, `svg` with its `class`, `viewBox`, `version`, `width`, `height` and `aria-hidden` and `path` with its `d` (the README's Documents gives the markup, and its Load the styles the `@aiquants/markdown` stylesheets that draw it). Inside it, as anywhere else, event handlers, `script`, `foreignObject`, `use` and `animate` are removed and URLs follow the rules above;
|
|
45
|
-
- `data-*` attributes survive only for the Markdown renderer's contract — `data-link-kind`, `data-doc-path`, `data-doc-exists`, `data-footnote-ref` and `data-footnote-backref` on links, `data-asset-src` and `data-asset-exists` on images, `data-footnotes` on sections, and the embed placeholder below — so the renderer's iframe plugin trigger (`data-plugin-type`) and the `<div data-plugin-type>` placeholders of `@aiquants/markdown` 5 never reach the browser; SVG and MathML pass through DOMPurify's own allow-lists;
|
|
45
|
+
- `data-*` attributes survive only for the Markdown renderer's contract — `data-link-kind`, `data-doc-path`, `data-doc-exists`, `data-footnote-ref` and `data-footnote-backref` on links, `data-asset-src` and `data-asset-exists` on images, `data-footnotes` on sections, `data-code-meta` on code (a ```spreadsheets table's options, an inert value), and the embed placeholder below — so the renderer's iframe plugin trigger (`data-plugin-type`) and the `<div data-plugin-type>` placeholders of `@aiquants/markdown` 5 never reach the browser; SVG and MathML pass through DOMPurify's own allow-lists;
|
|
46
46
|
- the embed placeholder, `data-embed-url` on a `<p>` (the converter's mark of a paragraph whose only content is one absolute `http(s)` link without credentials, holding the link's `href` byte for byte), survives only where `placeholderLinkOf` of `@aiquants/markdown/embeds` accepts it, whatever the provider.
|
|
47
47
|
DOMPurify visits a parent before its children, so the sanitizer records the paragraph's attribute as parsed and, once DOMPurify is done with the attributes of a link directly inside that paragraph, restores it only when the paragraph holds exactly that one link (besides comments, white space, U+00A0 and U+3000) and the parsed attribute value equals the link's `href` as DOMPurify trimmed it.
|
|
48
48
|
A padded attribute value, another `href`, an `href` DOMPurify removed (`javascript:`, `data:`), a relative or credential-bearing URL, a second link, text, any other element (even one after the link that DOMPurify then removes) or the attribute on another element leaves the paragraph and its link without it; a duplicated attribute is read as its first occurrence, as the HTML parser keeps it. A forged placeholder can therefore at most re-create what the converter writes for the bare link, and the viewer validates it again before it embeds or cards anything.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiquants/markdown-explorer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Markdown document explorer for React Router 8 (framework mode): a source tree with a single-document view and a multi-panel reading view, storage-agnostic server ports, golden-ratio layout and an en / ja UI.",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"**/*.css"
|
|
@@ -68,21 +68,23 @@
|
|
|
68
68
|
"parse5": "^8.0.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@aiquants/directory-tree": "^
|
|
71
|
+
"@aiquants/directory-tree": "^5.0.1",
|
|
72
72
|
"@aiquants/drag-drop-panels": "^0.12.0",
|
|
73
|
-
"@aiquants/markdown": "^
|
|
73
|
+
"@aiquants/markdown": "^9.0.1",
|
|
74
74
|
"@aiquants/resize-panels": "^2.2.0",
|
|
75
|
-
"@aiquants/
|
|
75
|
+
"@aiquants/spreadsheet": "^0.15.0",
|
|
76
|
+
"@aiquants/virtualscroll": "^3.22.1",
|
|
76
77
|
"react": "^19.2.7",
|
|
77
78
|
"react-dom": "^19.2.7",
|
|
78
79
|
"react-router": "^8.0.0"
|
|
79
80
|
},
|
|
80
81
|
"devDependencies": {
|
|
81
|
-
"@aiquants/directory-tree": "
|
|
82
|
+
"@aiquants/directory-tree": "5.0.1",
|
|
82
83
|
"@aiquants/drag-drop-panels": "0.12.0",
|
|
83
|
-
"@aiquants/markdown": "
|
|
84
|
+
"@aiquants/markdown": "9.0.1",
|
|
84
85
|
"@aiquants/resize-panels": "2.2.0",
|
|
85
|
-
"@aiquants/
|
|
86
|
+
"@aiquants/spreadsheet": "0.15.0",
|
|
87
|
+
"@aiquants/virtualscroll": "3.22.1",
|
|
86
88
|
"@heroicons/react": "^2.2.0",
|
|
87
89
|
"@playwright/test": "^1.59.1",
|
|
88
90
|
"@tailwindcss/cli": "^4.1.18",
|