From f98a46a5616741074b7d880254f35fc067ebf2b1 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Fri, 18 Apr 2025 23:30:24 +0300 Subject: [PATCH] cmd/syntax: small program to generate dark/light syntax highlighting css --- cmd/syntax/chroma.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 cmd/syntax/chroma.go diff --git a/cmd/syntax/chroma.go b/cmd/syntax/chroma.go new file mode 100644 index 00000000..619865fc --- /dev/null +++ b/cmd/syntax/chroma.go @@ -0,0 +1,41 @@ +package main + +import ( + "flag" + "fmt" + "os" + + "github.com/alecthomas/chroma/v2/formatters/html" + "github.com/alecthomas/chroma/v2/styles" +) + +var ( + lightTheme = "catppuccin-latte" + darkTheme = "catppuccin-macchiato" +) + +func main() { + outFile := flag.String("out", "", "css output file path") + flag.Parse() + + if *outFile == "" { + fmt.Println("error: output file path is required") + flag.Usage() + os.Exit(1) + } + + file, err := os.Create(*outFile) + if err != nil { + fmt.Printf("error creating file: %v\n", err) + os.Exit(1) + } + defer file.Close() + + formatter := html.New(html.WithClasses(true)) + + formatter.WriteCSS(file, styles.Get(lightTheme)) + + file.WriteString("\n@media (prefers-color-scheme: dark) {\n") + formatter.WriteCSS(file, styles.Get(darkTheme)) + file.WriteString("}\n") +} -- 2.54.0