feat: render TeX from UI class

This commit is contained in:
Oliver Booth 2023-08-10 15:28:53 +01:00
parent f3ad04ff1f
commit 28f310e315
Signed by: oliverbooth
GPG Key ID: 725DB725A0D9EE61
2 changed files with 18 additions and 11 deletions

View File

@ -1,4 +1,6 @@
class UI {
declare const katex: any;
class UI {
public static get blogPostContainer(): HTMLDivElement {
return document.querySelector("#all-blog-posts");
}
@ -12,6 +14,7 @@
*/
public static updateUI() {
UI.addLineNumbers();
UI.renderTeX();
UI.unescapeMarkTags();
}
@ -27,6 +30,20 @@
});
}
/**
* Renders all TeX in the document.
*/
public static renderTeX() {
const tex = document.getElementsByClassName("math");
Array.from(tex).forEach(function (el: Element) {
let content = el.textContent.trim();
if (content.startsWith("\\[")) content = content.slice(2);
if (content.endsWith("\\]")) content = content.slice(0, -2);
katex.render(content, el);
});
}
/**
* Unescapes all <mark> tags in <pre> <code> blocks.
*/

View File

@ -3,7 +3,6 @@ import TimeUtility from "./TimeUtility";
import UI from "./UI";
declare const bootstrap: any;
declare const katex: any;
declare const Handlebars: any;
(() => {
@ -59,15 +58,6 @@ declare const Handlebars: any;
UI.updateUI();
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);
});
const timestamps = document.querySelectorAll("span[data-timestamp][data-format]");
timestamps.forEach((timestamp) => {
const seconds = parseInt(timestamp.getAttribute("data-timestamp"));