oliverbooth.dev/src/ts/app.ts

38 lines
1.3 KiB
TypeScript
Raw Normal View History

declare const bootstrap: any;
2023-08-08 01:08:50 +00:00
declare const katex: any;
2023-08-04 11:55:16 +00:00
(() => {
2023-08-08 01:10:17 +00:00
document.querySelectorAll("pre code").forEach((block) => {
let content = block.textContent;
if (content.trim().split("\n").length > 1) {
2023-08-08 01:10:17 +00:00
block.parentElement.classList.add("line-numbers");
}
content = block.innerHTML;
// @ts-ignore
content = content.replaceAll("&lt;mark&gt;", "<mark>");
// @ts-ignore
content = content.replaceAll("&lt;/mark&gt;", "</mark>");
block.innerHTML = content;
2023-08-08 01:10:17 +00:00
});
document.querySelectorAll("[title]").forEach((img) => {
2023-08-08 01:10:42 +00:00
img.setAttribute("data-bs-toggle", "tooltip");
img.setAttribute("data-bs-placement", "bottom");
img.setAttribute("data-bs-html", "true");
img.setAttribute("data-bs-title", img.getAttribute("title"));
});
2023-08-08 01:08:18 +00:00
const list = document.querySelectorAll('[data-bs-toggle="tooltip"]');
list.forEach((el: Element) => new bootstrap.Tooltip(el));
2023-08-08 01:08:50 +00:00
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);
2023-08-08 01:08:50 +00:00
katex.render(content, el);
});
2023-08-04 11:55:16 +00:00
})();