2023-06-02 06:05:14 +07:00
|
|
|
import { QuartzTransformerPlugin } from "../types"
|
2024-02-18 01:23:45 +07:00
|
|
|
import rehypePrettyCode, { Options as CodeOptions, Theme as CodeTheme } from "rehype-pretty-code"
|
2023-06-02 06:05:14 +07:00
|
|
|
|
2024-02-18 01:23:45 +07: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 07:27:41 +07:00
|
|
|
},
|
2024-02-18 01:23:45 +07:00
|
|
|
keepBackground: false,
|
|
|
|
}
|
|
|
|
|
2024-08-09 08:28:13 +07:00
|
|
|
export const SyntaxHighlighting: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
|
|
|
|
const opts: CodeOptions = { ...defaultOptions, ...userOpts }
|
2024-02-18 01:23:45 +07:00
|
|
|
|
|
|
|
return {
|
|
|
|
name: "SyntaxHighlighting",
|
|
|
|
htmlPlugins() {
|
|
|
|
return [[rehypePrettyCode, opts]]
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|