2023-06-02 06:05:14 +07:00
|
|
|
import { QuartzTransformerPlugin } from "../types"
|
|
|
|
import rehypePrettyCode, { Options as CodeOptions } from "rehype-pretty-code"
|
|
|
|
|
2023-06-12 13:26:43 +07:00
|
|
|
export const SyntaxHighlighting: QuartzTransformerPlugin = () => ({
|
|
|
|
name: "SyntaxHighlighting",
|
|
|
|
markdownPlugins() {
|
2023-06-02 06:05:14 +07:00
|
|
|
return []
|
2023-06-12 13:26:43 +07:00
|
|
|
},
|
|
|
|
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.push('highlighted')
|
|
|
|
},
|
|
|
|
onVisitHighlightedWord(node) {
|
|
|
|
node.properties.className = ['word']
|
|
|
|
},
|
|
|
|
} satisfies Partial<CodeOptions>]]
|
|
|
|
}
|
2023-06-12 13:26:43 +07:00
|
|
|
})
|