Files
mtdb_movie/common/resources/client/text-editor/highlight/highlight-code.ts
T
maher 511fad8199
Build / run (push) Has been cancelled
Initial commit
2026-05-14 13:42:10 +02:00

20 lines
520 B
TypeScript
Executable File

export function highlightAllCode(
el: HTMLElement,
themeMode: 'light' | 'dark' = 'dark',
) {
el.querySelectorAll('pre code').forEach(e => {
highlightCode(e as HTMLElement, themeMode);
});
}
export async function highlightCode(
el: HTMLElement,
themeMode: 'light' | 'dark' = 'dark',
) {
const {hljs} = await import('@common/text-editor/highlight/highlight');
if (!el.dataset.highlighted) {
el.classList.add(themeMode === 'dark' ? 'hljs-dark' : 'hljs-light');
hljs.highlightElement(el);
}
}