Spaces:
Sleeping
Sleeping
Lê Đăng Khoa (Liam) commited on
upd mermaid
Browse files1402 unmodified lines1403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261402 unmodified lines}// ---------- Mermaid ----------function renderMermaid() {if (!window.mermaid) return;const theme = document.documentElement.classList.contains('dark') ? 'dark' : 'default';mermaid.initialize({startOnLoad: false,theme,securityLevel: 'loose',fontFamily: 'Inter, ui-sans-serif, system-ui',flowchart: { useMaxWidth: true, htmlLabels: true }});// Re-render all mermaid blocksconst blocks = $$('.mermaid');blocks.forEach((el, i) => {const code = el.textContent;const id = `mmd-${i}-${Date.now()}`;el.innerHTML = '';mermaid.render(id, code).then(({ svg }) => { el.innerHTML = svg; }).catch(() => {});});}// ---------- KaTeX ----------1402 unmodified lines14031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481402 unmodified lines}// ---------- Mermaid ----------async function renderMermaid() {if (!window.mermaid) return;const isDark = document.documentElement.classList.contains('dark');mermaid.initialize({startOnLoad: false,theme: isDark ? 'dark' : 'default',securityLevel: 'loose',fontFamily: 'Inter, ui-sans-serif, system-ui',flowchart: { useMaxWidth: true, htmlLabels: true }});const blocks = document.querySelectorAll('.mermaid');let idx = 0;for (const el of blocks) {// 1) Cache original source once (before SVG replacement)if (!el.dataset.mermaidSrc) {const src = (el.textContent || '').trim();// If the element already contains svg (e.g., from previous render), don't overwrite cacheif (src.startsWith('<svg')) continue;el.dataset.mermaidSrc = src;}const code = (el.dataset.mermaidSrc || '').trim();if (!code) continue;// 2) Render from cached sourceconst id = `mmd-${idx++}-${Date.now()}`;try {const { svg, bindFunctions } = await mermaid.render(id, code);el.innerHTML = svg;if (typeof bindFunctions === 'function') bindFunctions(el);} catch (err) {console.error('Mermaid render error:', err, code);const safe = String(err).replace(/</g, '<').replace(/>/g, '>');el.innerHTML = `<div class="text-red-300 text-sm">Mermaid render failed: ${safe}</div>`;}}}// ---------- KaTeX ----------
index.html+33-11