roadmap/quartz/plugins/transformers/syntax.ts

26 lines
731 B
TypeScript
Raw Normal View History

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