2023-06-01 23:05:14 +00:00
|
|
|
import { QuartzTransformerPlugin } from "../types"
|
2024-02-17 18:23:45 +00:00
|
|
|
import rehypePrettyCode, { Options as CodeOptions, Theme as CodeTheme } from "rehype-pretty-code"
|
2023-06-01 23:05:14 +00:00
|
|
|
|
2024-02-17 18:23:45 +00:00
|
|
|
interface Theme extends Record<string, CodeTheme> {
|
|
|
|
light: CodeTheme
|
|
|
|
dark: CodeTheme
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Options {
|
|
|
|
theme?: Theme
|
|
|
|
keepBackground?: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultOptions: Options = {
|
|
|
|
theme: {
|
|
|
|
light: "github-light",
|
|
|
|
dark: "github-dark",
|
2023-07-23 00:27:41 +00:00
|
|
|
},
|
2024-02-17 18:23:45 +00:00
|
|
|
keepBackground: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
export const SyntaxHighlighting: QuartzTransformerPlugin<Options> = (
|
|
|
|
userOpts?: Partial<Options>,
|
|
|
|
) => {
|
|
|
|
const opts: Partial<CodeOptions> = { ...defaultOptions, ...userOpts }
|
|
|
|
|
|
|
|
return {
|
|
|
|
name: "SyntaxHighlighting",
|
|
|
|
htmlPlugins() {
|
|
|
|
return [[rehypePrettyCode, opts]]
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|