Spaces:
Sleeping
Sleeping
upd mermaid
Browse files- index.html +33 -11
index.html
CHANGED
|
@@ -1403,24 +1403,46 @@ L_t = α * CE(y_t) + (1-α) * τ^2 * KL( p_T(·|τ) || p_S(·) )</code></pre>
|
|
| 1403 |
}
|
| 1404 |
|
| 1405 |
// ---------- Mermaid ----------
|
| 1406 |
-
function renderMermaid() {
|
| 1407 |
if (!window.mermaid) return;
|
| 1408 |
-
|
|
|
|
| 1409 |
mermaid.initialize({
|
| 1410 |
startOnLoad: false,
|
| 1411 |
-
theme,
|
| 1412 |
securityLevel: 'loose',
|
| 1413 |
fontFamily: 'Inter, ui-sans-serif, system-ui',
|
| 1414 |
flowchart: { useMaxWidth: true, htmlLabels: true }
|
| 1415 |
});
|
| 1416 |
-
|
| 1417 |
-
const blocks =
|
| 1418 |
-
|
| 1419 |
-
|
| 1420 |
-
|
| 1421 |
-
|
| 1422 |
-
|
| 1423 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1424 |
}
|
| 1425 |
|
| 1426 |
// ---------- KaTeX ----------
|
|
|
|
| 1403 |
}
|
| 1404 |
|
| 1405 |
// ---------- Mermaid ----------
|
| 1406 |
+
async function renderMermaid() {
|
| 1407 |
if (!window.mermaid) return;
|
| 1408 |
+
|
| 1409 |
+
const isDark = document.documentElement.classList.contains('dark');
|
| 1410 |
mermaid.initialize({
|
| 1411 |
startOnLoad: false,
|
| 1412 |
+
theme: isDark ? 'dark' : 'default',
|
| 1413 |
securityLevel: 'loose',
|
| 1414 |
fontFamily: 'Inter, ui-sans-serif, system-ui',
|
| 1415 |
flowchart: { useMaxWidth: true, htmlLabels: true }
|
| 1416 |
});
|
| 1417 |
+
|
| 1418 |
+
const blocks = document.querySelectorAll('.mermaid');
|
| 1419 |
+
let idx = 0;
|
| 1420 |
+
|
| 1421 |
+
for (const el of blocks) {
|
| 1422 |
+
// 1) Cache original source once (before SVG replacement)
|
| 1423 |
+
if (!el.dataset.mermaidSrc) {
|
| 1424 |
+
const src = (el.textContent || '').trim();
|
| 1425 |
+
// If the element already contains svg (e.g., from previous render), don't overwrite cache
|
| 1426 |
+
if (src.startsWith('<svg')) continue;
|
| 1427 |
+
el.dataset.mermaidSrc = src;
|
| 1428 |
+
}
|
| 1429 |
+
|
| 1430 |
+
const code = (el.dataset.mermaidSrc || '').trim();
|
| 1431 |
+
if (!code) continue;
|
| 1432 |
+
|
| 1433 |
+
// 2) Render from cached source
|
| 1434 |
+
const id = `mmd-${idx++}-${Date.now()}`;
|
| 1435 |
+
|
| 1436 |
+
try {
|
| 1437 |
+
const { svg, bindFunctions } = await mermaid.render(id, code);
|
| 1438 |
+
el.innerHTML = svg;
|
| 1439 |
+
if (typeof bindFunctions === 'function') bindFunctions(el);
|
| 1440 |
+
} catch (err) {
|
| 1441 |
+
console.error('Mermaid render error:', err, code);
|
| 1442 |
+
const safe = String(err).replace(/</g, '<').replace(/>/g, '>');
|
| 1443 |
+
el.innerHTML = `<div class="text-red-300 text-sm">Mermaid render failed: ${safe}</div>`;
|
| 1444 |
+
}
|
| 1445 |
+
}
|
| 1446 |
}
|
| 1447 |
|
| 1448 |
// ---------- KaTeX ----------
|