docs: annotate all shared frontend modules in Chinese

This commit is contained in:
cieanyau committed 2026-11-06 00:30:15 +08:00
1 parent 2be21c1c62
commit 408f8e5c98
55 files changed
+349

No files matched your search

+7
View File
@@ -1,3 +1,7 @@
/**
* 在浏览器 DOM 中重新构造允许的富文本,不直接信任后端商品/内容 HTML。
* 白名单外的普通容器展开子内容;script、表单和非 HTML 命名空间整段丢弃。
*/
var e = new Set(
`a.p.br.hr.div.span.h1.h2.h3.h4.h5.h6.b.strong.i.em.u.s.del.ins.sub.sup.small.mark.blockquote.pre.code.kbd.ul.ol.li.dl.dt.dd.table.thead.tbody.tfoot.tr.th.td.caption.colgroup.col.img.figure.figcaption`.split(
`.`,
@@ -30,6 +34,7 @@ var e = new Set(
`video`,
`source`,
]);
// 图片额外允许有限位图类型的 base64 data URL;普通链接可用 mailto/tel,不允许脚本协议。
function n(e, t = !1) {
if (!e || /[\u0000-\u001f\u007f]/.test(e)) return !1;
if (
@@ -48,6 +53,7 @@ function n(e, t = !1) {
return !1;
}
}
/** 清洗标签和属性,只保留有限排版;新窗口链接强制添加 noopener noreferrer。 */
function r(r) {
if (!r) return ``;
let i = new DOMParser().parseFromString(r, `text/html`),
@@ -103,6 +109,7 @@ function r(r) {
for (let e of Array.from(i.body.childNodes)) o(e, a);
return a.innerHTML;
}
// 对历史双重实体编码最多解码两次;返回值只是解码文本,不能代替上面的 HTML 清洗。
function i(e) {
if (!e) return ``;
let t = e;