1package main
2
3import (
4 "flag"
5 "fmt"
6 "os"
7
8 "github.com/alecthomas/chroma/v2/formatters/html"
9 "github.com/alecthomas/chroma/v2/styles"
10)
11
12var (
13 lightTheme = "catppuccin-latte"
14 darkTheme = "catppuccin-macchiato"
15)
16
17const (
18 targetHl = `
19 .chroma .line:has(.ln:target) {
20 background-color: rgba(140, 143, 161, 0.3);
21 }
22
23 @media (prefers-color-scheme: dark) {
24 .chroma .line:has(.ln:target) {
25 background-color: rgba(128, 135, 162, 0.3);
26 }
27 }
28 `
29)
30
31func main() {
32 outFile := flag.String("out", "", "css output file path")
33 flag.Parse()
34
35 if *outFile == "" {
36 fmt.Println("error: output file path is required")
37 flag.Usage()
38 os.Exit(1)
39 }
40
41 file, err := os.Create(*outFile)
42 if err != nil {
43 fmt.Printf("error creating file: %v\n", err)
44 os.Exit(1)
45 }
46 defer file.Close()
47
48 formatter := html.New(html.WithClasses(true))
49
50 formatter.WriteCSS(file, styles.Get(lightTheme))
51
52 file.WriteString("\n@media (prefers-color-scheme: dark) {\n")
53 formatter.WriteCSS(file, styles.Get(darkTheme))
54 file.WriteString("}\n")
55
56 file.WriteString(targetHl)
57}