(() => {
if (window.__textusRender) return;
window.__textusRender = true;
const config = __TEXTUS_CONFIG__;
const report = (error) => console.error("textus rendering:", error);
__TEXTUS_ALERTS__
const start = async () => {
const root = document.querySelector('meta[name="rustdoc-vars"]')?.dataset.rootPath;
if (root === undefined) { report("rustdoc root path is missing"); return; }
const base = new URL(root + "textus-assets/", location.href);
const script = (name) => new Promise((resolve, reject) => {
const element = document.createElement("script");
element.src = new URL(name, base).href;
element.onload = resolve;
element.onerror = () => reject(new Error(`could not load ${name}`));
document.head.append(element);
});
const style = (name) => {
const element = document.createElement("link");
element.rel = "stylesheet";
element.href = new URL(name, base).href;
document.head.append(element);
};
if (config.math) style("katex.css");
if (config.alerts) style("alerts.css");
for (const name of config.css) style(name);
const docs = [...document.querySelectorAll(".docblock")];
if (config.alerts) renderAlerts(docs);
await Promise.all([
(async () => {
if (!config.mermaid) return;
await script("mermaid.js");
mermaid.initialize({startOnLoad: false, securityLevel: "strict"});
for (const doc of docs) {
for (const code of doc.querySelectorAll("pre.language-mermaid, code.language-mermaid")) {
const pre = code.closest("pre");
if (pre) { pre.classList.add("mermaid"); pre.textContent = code.textContent; }
}
}
await mermaid.run({querySelector: ".docblock .mermaid", suppressErrors: true});
})().catch(report),
(async () => {
if (!config.math) return;
await script("katex.js");
await script("auto-render.js");
for (const doc of docs) {
renderMathInElement(doc, {
delimiters: [
{left: "$$", right: "$$", display: true},
{left: "$", right: "$", display: false},
],
ignoredClasses: ["mermaid", "katex", "textus-no-math"],
throwOnError: false,
trust: false,
});
}
})().catch(report),
]);
for (const name of config.js) {
try { await script(name); } catch (error) { report(error); }
}
document.documentElement.dataset.textusRendered = "true";
};
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", start, {once: true});
else start();
})();