@cartamd/plugin-code
Version:
This plugin adds support for code blocks **syntax highlighting**. It uses the same highlighter from the core package(Shiki).
34 lines • 1.41 kB
JavaScript
import rehypeShikiFromHighlighter from '@shikijs/rehype/core';
/**
* Carta code highlighting plugin. Themes available on [GitHub](https://github.com/speed-highlight/core/tree/main/dist/themes).
*/
export const code = (options) => {
return {
transformers: [
{
execution: 'async',
type: 'rehype',
async transform({ processor, carta }) {
let theme = options?.theme;
const highlighter = await carta.highlighter();
if (highlighter) {
const shikiHighlighter = highlighter.shikiHighlighter();
if (!theme) {
theme = highlighter.settings.themeHash; // Use the theme specified in the highlighter
}
if (highlighter.utils.isSingleTheme(theme)) {
processor.use(rehypeShikiFromHighlighter, shikiHighlighter, { ...options, theme });
}
else {
processor.use(rehypeShikiFromHighlighter, shikiHighlighter, {
...options,
themes: theme
});
}
}
}
}
]
};
};
//# sourceMappingURL=index.js.map