/** * app.js — Main logic for sunvpy static documentation site. * Handles routing, markdown rendering, navigation, TOC, and theme. */ (function () { "use strict"; // --- State --- let navData = null; let flatPages = []; // ordered array of all slugs let currentPage = null; let isDark = false; let mermaidInitialized = false; // --- DOM refs --- const sidebarNav = document.getElementById("sidebarNav"); const article = document.getElementById("article"); const pageNav = document.getElementById("pageNav"); const tocNav = document.getElementById("tocNav"); const contentEl = document.getElementById("content"); // --- Init --- async function init() { // Theme const saved = localStorage.getItem("sunvpy-theme"); if (saved === "dark" || (!saved && window.matchMedia("(prefers-color-scheme: dark)").matches)) { setTheme(true, false); } // Load nav try { const resp = await fetch("data/nav.json"); navData = await resp.json(); } catch (e) { article.innerHTML = '
" + text + "
"; }; // Add IDs to headings var headingIndex = {}; renderer.heading = function (text, depth) { // marked v15 passes heading data as object or text+depth var headingText = typeof text === "object" ? text.text : text; var headingDepth = typeof text === "object" ? text.depth : depth; var raw = headingText.replace(/<[^>]+>/g, ""); var baseId = raw.toLowerCase() .replace(/[^\w\u4e00-\u9fff]+/g, "-") .replace(/^-|-$/g, ""); if (!baseId) baseId = "heading"; if (headingIndex[baseId] !== undefined) { headingIndex[baseId]++; baseId = baseId + "-" + headingIndex[baseId]; } else { headingIndex[baseId] = 0; } return '" + langLabel + '' + highlighted + "";
};
marked.use({
renderer: renderer,
gfm: true,
breaks: false,
});
// Render
var html;
try {
html = marked.parse(md);
} catch (e) {
console.error("Markdown render error:", e);
article.innerHTML = '