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