mirror of
https://github.com/jaandrle/deka-dom-el
synced 2024-11-23 00:59:38 +01:00
20 lines
457 B
JavaScript
20 lines
457 B
JavaScript
|
const langs= {
|
||
|
javascript: 'js',
|
||
|
js: 'js',
|
||
|
html: 'html',
|
||
|
};
|
||
|
|
||
|
const highlighter= await shiki.getHighlighter({
|
||
|
theme: 'css-variables',
|
||
|
langs: ['js', 'html', 'shell'],
|
||
|
});
|
||
|
const codeBlocks= document.querySelectorAll('pre code[class*="language-"]');
|
||
|
|
||
|
codeBlocks.forEach((block)=> {
|
||
|
const lang= block.className.replace('language-', '');
|
||
|
const html= highlighter.codeToHtml(block.textContent, {
|
||
|
lang: langs[lang] || lang,
|
||
|
});
|
||
|
block.innerHTML= html;
|
||
|
});
|