import { thp_highlighter, CodeJar } from "../lexer/highlighter"; /** * Highlights all THP code snippets mounted in the DOM with class .language-thp * * It assumes that the code is inside:
...
 */
export function highlightOnDom() {
    const code_elements = document.querySelectorAll("code.language-thp");

    for (const e of [...code_elements]) {
        const el = e as HTMLElement;
        // Some elements with .language-thp don't want to be processed
        if (e.getAttribute("data-disabled") !== null) {
            continue;
        }

        const pre_parent = el.parentElement!;
        const new_div = document.createElement("div");
        const code = el.innerText;

        el.parentElement!.className = "language-thp";
        pre_parent.removeChild(el);
        pre_parent.appendChild(new_div);

        CodeJar(new_div, thp_highlighter, {
            tab: "    ",
        }).updateCode(code);
    }
}