(function () {
var script = document.currentScript;
var nonce = script && script.nonce;
var jsSrc = script && script.dataset.katexJs;
var cssSrc = script && script.dataset.katexCss;
var loading = null;
function load() {
if (window.katex && typeof window.katex.render === "function") return Promise.resolve();
if (!jsSrc) return Promise.reject(new Error("KaTeX not available"));
if (!loading) {
loading = Promise.all([
add("link", { rel: "stylesheet", href: cssSrc }),
add("script", { src: jsSrc, nonce: nonce }),
]).catch(function (e) { loading = null; throw e; });
}
return loading;
}
function add(tag, attrs) {
return new Promise(function (resolve, reject) {
var el = document.createElement(tag);
for (var k in attrs) el[k] = attrs[k];
el.onload = resolve;
el.onerror = function () { reject(new Error("failed to load " + (attrs.src || attrs.href))); };
document.head.appendChild(el);
});
}
async function render(root) {
var nodes = root.querySelectorAll("[data-math-style]");
if (!nodes.length) return;
await load();
for (var i = 0; i < nodes.length; i++) {
var el = nodes[i];
var display = el.getAttribute("data-math-style") === "display";
var target = el.tagName === "CODE" && el.parentElement.tagName === "PRE"
? el.parentElement : el;
var out = document.createElement(display ? "div" : "span");
out.className = display ? "math math-display" : "math math-inline";
var pos = target.getAttribute("data-sourcepos") || el.getAttribute("data-sourcepos");
if (pos) out.setAttribute("data-sourcepos", pos);
window.katex.render(el.textContent.trim(), out, {
displayMode: display,
throwOnError: false,
});
target.replaceWith(out);
}
}
(window.mdvEnhancers = window.mdvEnhancers || []).push(render);
(window.mdvInitial = window.mdvInitial || []).push(render(document.querySelector(".markdown-body")).catch(function (e) {
console.error("markdown-viewer:", e);
}));
})();