feat: render TeX from UI class
This commit is contained in:
parent
f3ad04ff1f
commit
28f310e315
19
src/ts/UI.ts
19
src/ts/UI.ts
|
@ -1,4 +1,6 @@
|
||||||
class UI {
|
declare const katex: any;
|
||||||
|
|
||||||
|
class UI {
|
||||||
public static get blogPostContainer(): HTMLDivElement {
|
public static get blogPostContainer(): HTMLDivElement {
|
||||||
return document.querySelector("#all-blog-posts");
|
return document.querySelector("#all-blog-posts");
|
||||||
}
|
}
|
||||||
|
@ -12,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
public static updateUI() {
|
public static updateUI() {
|
||||||
UI.addLineNumbers();
|
UI.addLineNumbers();
|
||||||
|
UI.renderTeX();
|
||||||
UI.unescapeMarkTags();
|
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.
|
* Unescapes all <mark> tags in <pre> <code> blocks.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,7 +3,6 @@ import TimeUtility from "./TimeUtility";
|
||||||
import UI from "./UI";
|
import UI from "./UI";
|
||||||
|
|
||||||
declare const bootstrap: any;
|
declare const bootstrap: any;
|
||||||
declare const katex: any;
|
|
||||||
declare const Handlebars: any;
|
declare const Handlebars: any;
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
|
@ -59,15 +58,6 @@ declare const Handlebars: any;
|
||||||
|
|
||||||
UI.updateUI();
|
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]");
|
const timestamps = document.querySelectorAll("span[data-timestamp][data-format]");
|
||||||
timestamps.forEach((timestamp) => {
|
timestamps.forEach((timestamp) => {
|
||||||
const seconds = parseInt(timestamp.getAttribute("data-timestamp"));
|
const seconds = parseInt(timestamp.getAttribute("data-timestamp"));
|
||||||
|
|
Loading…
Reference in New Issue