1//go:build ignore
2
3package main
4
5import (
6 "bytes"
7 "log"
8 "os"
9 "path/filepath"
10
11 "github.com/alecthomas/chroma/v2/formatters/html"
12 "github.com/alecthomas/chroma/v2/styles"
13)
14
15func main() {
16 lightStyle := styles.Get("github")
17 if lightStyle == nil {
18 log.Fatal("github style not found")
19 }
20
21 darkStyle := styles.Get("github-dark")
22 if darkStyle == nil {
23 log.Fatal("github-dark style not found")
24 }
25
26 formatter := html.New(html.WithClasses(true))
27
28 var buf bytes.Buffer
29
30 buf.WriteString("/* Auto-generated syntax highlighting CSS */\n")
31 buf.WriteString("/* Generated by go generate - do not edit manually */\n\n")
32
33 buf.WriteString("@media (prefers-color-scheme: light) {\n")
34 if err := formatter.WriteCSS(&buf, lightStyle); err != nil {
35 log.Fatalf("failed to write light style CSS: %v", err)
36 }
37 buf.WriteString("}\n\n")
38
39 buf.WriteString("@media (prefers-color-scheme: dark) {\n")
40 if err := formatter.WriteCSS(&buf, darkStyle); err != nil {
41 log.Fatalf("failed to write dark style CSS: %v", err)
42 }
43 buf.WriteString("}\n")
44
45 outputPath := filepath.Join("static", "syntax.css")
46 if err := os.WriteFile(outputPath, buf.Bytes(), 0o644); err != nil {
47 log.Fatalf("failed to write CSS file: %v", err)
48 }
49
50 log.Printf("Generated %s successfully", outputPath)
51}