From 204269396eb64580f8dd2b889b37c1ad84c3fb69 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 8 Aug 2023 02:08:50 +0100 Subject: [PATCH] feat: use KaTeX to render math exprs --- src/ts/app.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ts/app.ts b/src/ts/app.ts index 87ddb7d..5c6c116 100644 --- a/src/ts/app.ts +++ b/src/ts/app.ts @@ -1,6 +1,18 @@ declare const bootstrap: any; +declare const katex: any; (() => { const list = document.querySelectorAll('[data-bs-toggle="tooltip"]'); list.forEach((el: Element) => new bootstrap.Tooltip(el)); + + window.onload = function () { + const tex = document.getElementsByClassName("math"); + Array.prototype.forEach.call(tex, function (el) { + let content = el.textContent.trim(); + if (content.startsWith("\\[")) content = content.slice(2); + if (content.endsWith("\\]")) content = content.slice(0, -2); + + katex.render(content, el); + }); + }; })();