2023-04-24 16:18:54 +02:00
|
|
|
window.addEventListener("load", () => {
|
2023-04-29 15:26:12 +02:00
|
|
|
/* Configuration */
|
2023-04-24 16:18:54 +02:00
|
|
|
hljs.configure({
|
|
|
|
noHighlightRe: /^$/i,
|
|
|
|
languageDetectRe: /\blanguage-hljs-([\w-]+)\b/i,
|
|
|
|
});
|
|
|
|
hljs.addPlugin(new CopyButtonPlugin());
|
2023-04-24 16:47:38 +02:00
|
|
|
|
2023-04-29 15:26:12 +02:00
|
|
|
/* Aliases of langs */
|
2023-04-24 16:47:38 +02:00
|
|
|
const aliases = {
|
|
|
|
bash: ["fish"],
|
2024-04-01 01:30:24 +02:00
|
|
|
julia: ["pseudocode"],
|
2023-04-24 16:47:38 +02:00
|
|
|
};
|
|
|
|
for (const lang in aliases) {
|
|
|
|
hljs.registerAliases(aliases[lang], { languageName: lang });
|
|
|
|
}
|
|
|
|
|
2023-04-29 15:26:12 +02:00
|
|
|
/* Highlight */
|
2023-04-24 16:18:54 +02:00
|
|
|
hljs.highlightAll();
|
2023-04-24 20:58:55 +02:00
|
|
|
hljs.initLineNumbersOnLoad();
|
2023-04-25 02:32:43 +02:00
|
|
|
|
2023-04-29 15:26:12 +02:00
|
|
|
/* Theme */
|
|
|
|
const dark = "dark";
|
|
|
|
const light = "light";
|
2023-04-29 15:26:55 +02:00
|
|
|
const attribute = "disabled";
|
2023-04-29 15:26:12 +02:00
|
|
|
const updateTheme = (theme) => {
|
|
|
|
{
|
|
|
|
const elementToEnable = document.getElementById(
|
|
|
|
`hljs-${theme.matches ? dark : light}-theme`
|
|
|
|
);
|
|
|
|
const elementToDisable = document.getElementById(
|
|
|
|
`hljs-${theme.matches ? light : dark}-theme`
|
|
|
|
);
|
|
|
|
|
2023-04-29 15:26:55 +02:00
|
|
|
if (elementToEnable.hasAttribute(attribute)) {
|
|
|
|
elementToEnable.removeAttribute(attribute);
|
2023-04-29 15:26:12 +02:00
|
|
|
}
|
2023-04-29 15:26:55 +02:00
|
|
|
elementToDisable.setAttribute(attribute, attribute);
|
2023-04-29 15:26:12 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const darkModePreference = window.matchMedia("(prefers-color-scheme: dark)");
|
|
|
|
updateTheme(darkModePreference);
|
|
|
|
|
|
|
|
darkModePreference.addEventListener("change", (theme) => updateTheme(theme));
|
2023-04-24 16:18:54 +02:00
|
|
|
});
|