first commit

This commit is contained in:
xiaomai
2025-09-15 00:28:27 +08:00
commit ae8d3ce510
28 changed files with 2882 additions and 0 deletions

32
20250916/ppt/js/engine.js Normal file
View File

@@ -0,0 +1,32 @@
function escapeHtml(str) {
if (str == null) return "";
return String(str)
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
}
export function renderTemplate(template, data = {}, opts = { allowRaw: true }) {
// 支持 nested keys (a.b.c)
const get = (path) =>
path
.split(".")
.reduce((acc, k) => (acc == null ? undefined : acc[k]), data);
return template.replace(
/\{\{\{\s*([\w$.]+)\s*\}\}\}|\{\{\s*([\w$.]+)\s*\}\}/g,
(m, rawKey, escKey) => {
const key = rawKey || escKey;
const val = get(key);
if (rawKey)
return opts.allowRaw
? val == null
? ""
: String(val)
: escapeHtml(val);
return val == null ? "" : escapeHtml(val);
}
);
}