Using Shiki in a Remark Plugin #219
-
I want to use the function below for my code blocks, but I've noticed that there isn't a good plugin or integration for using I've never build a plugin before, any suggestions on what's the easiest way to do so? I am thinking it would have to be a remark plugin that would require to walk to tree, identify the correct node type and then return the right HTML. I'm trying to keep it as simple as possible. import { getHighlighter, Lang, Theme } from "shiki";
type options = { lang: Lang; theme: Theme };
export async function highlight(code: string, { lang, theme }: options) {
const highlighter = await getHighlighter({ theme });
return highlighter.codeToHtml(code, { lang });
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Heya @ekqt! 👋 First you may want to check out the existing integrations.
If those don't meet your needs, https://unifiedjs.com/learn/ introduces abstract syntax trees and working with ASTs using plugins. |
Beta Was this translation helpful? Give feedback.
Heya @ekqt! 👋
First you may want to check out the existing integrations.
If those don't meet your needs, https://unifiedjs.com/learn/ introduces abstract syntax trees and working with ASTs using plugins.