+41
cmd/syntax/chroma.go
+41
cmd/syntax/chroma.go
···
1
+
package main
2
+
3
+
import (
4
+
"flag"
5
+
"fmt"
6
+
"os"
7
+
8
+
"github.com/alecthomas/chroma/v2/formatters/html"
9
+
"github.com/alecthomas/chroma/v2/styles"
10
+
)
11
+
12
+
var (
13
+
lightTheme = "catppuccin-latte"
14
+
darkTheme = "catppuccin-macchiato"
15
+
)
16
+
17
+
func main() {
18
+
outFile := flag.String("out", "", "css output file path")
19
+
flag.Parse()
20
+
21
+
if *outFile == "" {
22
+
fmt.Println("error: output file path is required")
23
+
flag.Usage()
24
+
os.Exit(1)
25
+
}
26
+
27
+
file, err := os.Create(*outFile)
28
+
if err != nil {
29
+
fmt.Printf("error creating file: %v\n", err)
30
+
os.Exit(1)
31
+
}
32
+
defer file.Close()
33
+
34
+
formatter := html.New(html.WithClasses(true))
35
+
36
+
formatter.WriteCSS(file, styles.Get(lightTheme))
37
+
38
+
file.WriteString("\n@media (prefers-color-scheme: dark) {\n")
39
+
formatter.WriteCSS(file, styles.Get(darkTheme))
40
+
file.WriteString("}\n")
41
+
}