fix: restore KaTeX assets and deployment checks
CI / test (pull_request) Canceled after 7s
PR合并自动部署 / release-check (pull_request) Successful in 1m40s
PR合并自动部署 / deploy (pull_request) Successful in 14s

This commit is contained in:
2026-08-09 03:47:17 +08:00
parent feb8845ec7
commit 3e47ba787d
68 changed files with 121 additions and 11 deletions
+34 -6
View File
@@ -1060,15 +1060,40 @@ function switchTool(tool) {
window.HuluToolbox?.activate(tool);
}
function normalizeLatexSource(source) {
let normalized = String(source || "").trim();
if (normalized.startsWith("$$") && normalized.endsWith("$$")) {
normalized = normalized.slice(2, -2).trim();
} else if (normalized.startsWith("\\[") && normalized.endsWith("\\]")) {
normalized = normalized.slice(2, -2).trim();
} else if (normalized.startsWith("$") && normalized.endsWith("$")) {
normalized = normalized.slice(1, -1).trim();
}
return normalized.replace(/\\\\(?=[A-Za-z,;:!])/g, "\\");
}
function renderLatexPreview(source) {
const target = $("#latex-preview");
target.replaceChildren();
if (!source.trim()) return;
if (typeof katex === "undefined") { target.textContent = source; return; }
target.classList.remove("latex-preview-error");
const normalized = normalizeLatexSource(source);
if (!normalized) return;
if (typeof globalThis.katex?.render !== "function") {
target.classList.add("latex-preview-error");
target.textContent = "公式渲染组件加载失败,请刷新页面后重试。";
return;
}
try {
katex.render(source, target, { throwOnError: false, displayMode: true });
} catch {
target.textContent = source;
globalThis.katex.render(normalized, target, {
displayMode: true,
throwOnError: true,
trust: false,
maxExpand: 500,
maxSize: 20,
});
} catch (error) {
target.classList.add("latex-preview-error");
target.textContent = `公式语法错误:${error.message}`;
}
}
@@ -1077,7 +1102,10 @@ async function saveFormula() {
try {
await api("latex/documents/", {
method: "POST",
body: { title: `公式 ${new Date().toLocaleString()}`, source: $("#latex-source").value },
body: {
title: `公式 ${new Date().toLocaleString()}`,
source: normalizeLatexSource($("#latex-source").value),
},
});
showToast("公式及首个版本已保存");
} catch (error) {