rizaldy.club/quartz/plugins/transformers/syntax.ts

25 lines
774 B
TypeScript
Raw Normal View History

2023-06-02 06:05:14 +07:00
import { QuartzTransformerPlugin } from "../types"
import rehypePrettyCode, { Options as CodeOptions } from "rehype-pretty-code"
export const SyntaxHighlighting: QuartzTransformerPlugin = () => ({
name: "SyntaxHighlighting",
htmlPlugins() {
2023-06-02 06:05:14 +07:00
return [[rehypePrettyCode, {
theme: 'css-variables',
onVisitLine(node) {
if (node.children.length === 0) {
node.children = [{ type: 'text', value: ' ' }]
}
},
onVisitHighlightedLine(node) {
node.properties.className ??= []
2023-06-02 06:05:14 +07:00
node.properties.className.push('highlighted')
},
onVisitHighlightedWord(node) {
node.properties.className ??= []
node.properties.className.push('word')
2023-06-02 06:05:14 +07:00
},
} satisfies Partial<CodeOptions>]]
}
})