mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-17 19:47:41 +01:00
33 lines
907 B
TypeScript
33 lines
907 B
TypeScript
|
|
import { bundledLanguages, type ThemeRegistration } from 'shikiji';
|
||
|
|
import { getHighlighter } from 'shikiji';
|
||
|
|
|
||
|
|
export type ThemeOptions =
|
||
|
|
| ThemeRegistration
|
||
|
|
| { light: ThemeRegistration; dark: ThemeRegistration };
|
||
|
|
|
||
|
|
const highLightCode = async (code: string, lang: string, active?: boolean) => {
|
||
|
|
const highlighter = await getHighlighter({
|
||
|
|
themes: ['github-light', 'github-dark'],
|
||
|
|
langs: Object.keys(bundledLanguages),
|
||
|
|
});
|
||
|
|
|
||
|
|
const highlightedCode = highlighter
|
||
|
|
.codeToHtml(code, {
|
||
|
|
lang,
|
||
|
|
themes: {
|
||
|
|
light: 'github-light',
|
||
|
|
dark: 'github-dark',
|
||
|
|
},
|
||
|
|
defaultColor: false,
|
||
|
|
})
|
||
|
|
.replace('shiki-themes', 'shiki-themes vp-code');
|
||
|
|
|
||
|
|
return `<div class="language-${lang} ${active ? 'active' : ''}">
|
||
|
|
<button title="Copy Code" class="copy"></button>
|
||
|
|
<span class="lang">${lang}</span>
|
||
|
|
${highlightedCode}
|
||
|
|
</div>`;
|
||
|
|
};
|
||
|
|
|
||
|
|
export default highLightCode;
|