| | |
| | | import { QuartzTransformerPlugin } from "../types" |
| | | import rehypePrettyCode, { Options as CodeOptions } from "rehype-pretty-code" |
| | | import rehypePrettyCode, { Options as CodeOptions, Theme as CodeTheme } from "rehype-pretty-code" |
| | | |
| | | export const SyntaxHighlighting: QuartzTransformerPlugin = () => ({ |
| | | name: "SyntaxHighlighting", |
| | | htmlPlugins() { |
| | | return [ |
| | | [ |
| | | rehypePrettyCode, |
| | | { |
| | | keepBackground: false, |
| | | theme: { |
| | | dark: "github-dark", |
| | | light: "github-light", |
| | | }, |
| | | } satisfies Partial<CodeOptions>, |
| | | ], |
| | | ] |
| | | 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", |
| | | }, |
| | | }) |
| | | keepBackground: false, |
| | | } |
| | | |
| | | export const SyntaxHighlighting: QuartzTransformerPlugin<Options> = ( |
| | | userOpts?: Partial<Options>, |
| | | ) => { |
| | | const opts: Partial<CodeOptions> = { ...defaultOptions, ...userOpts } |
| | | |
| | | return { |
| | | name: "SyntaxHighlighting", |
| | | htmlPlugins() { |
| | | return [[rehypePrettyCode, opts]] |
| | | }, |
| | | } |
| | | } |