Files
kopyl.dev.v2/shikiHighlighter.js
Anatoly Kopyl 93f92efefc
All checks were successful
Deploy / build-and-publish (push) Successful in 1m48s
Deploy / deploy (push) Successful in 13s
New article
2024-10-08 02:15:02 +03:00

40 lines
745 B
JavaScript

import {createHighlighter} from "shiki"
import {escapeSvelte} from "mdsvex"
import {
transformerNotationHighlight,
transformerNotationDiff
} from "@shikijs/transformers"
const theme = 'material-theme'
export const highlighter = await createHighlighter({
themes: [theme],
langs: [
'javascript',
'typescript',
'html',
'markdown',
'mdx',
'bash',
'svelte',
'yaml',
'lua',
'python'
]
});
export const shikiHighlighter = async (code, lang = 'text') => {
const html = escapeSvelte(highlighter.codeToHtml(
code,
{
lang,
theme,
transformers: [
transformerNotationHighlight(),
transformerNotationDiff()
]
}
));
return `{@html \`${html}\` }`;
}