main
1package main
2
3import (
4 "os"
5 "path/filepath"
6 "runtime"
7 "strings"
8
9 "github.com/alecthomas/chroma/v2/formatters/html"
10 "github.com/alecthomas/chroma/v2/styles"
11)
12
13func main() {
14 _, file, _, _ := runtime.Caller(0)
15 cssDir := filepath.Join(filepath.Dir(file), "../../internal/templates/css")
16
17 formatter := html.New(
18 html.WithLineNumbers(true),
19 html.WithLinkableLineNumbers(true, "L"),
20 html.WithClasses(true),
21 )
22
23 lightStyle := styles.Get("github")
24 darkStyle := styles.Get("github-dark")
25
26 var light, dark strings.Builder
27 _ = formatter.WriteCSS(&light, lightStyle)
28 _ = formatter.WriteCSS(&dark, darkStyle)
29
30 light.WriteString(".chroma .gi { display: block; }\n")
31 light.WriteString(".chroma .gd { display: block; }\n")
32 dark.WriteString(".chroma .gi { display: block; }\n")
33 dark.WriteString(".chroma .gd { display: block; }\n")
34
35 if err := os.WriteFile(filepath.Join(cssDir, "syntax_light.css"), []byte(light.String()), 0o644); err != nil {
36 panic(err)
37 }
38 if err := os.WriteFile(filepath.Join(cssDir, "syntax_dark.css"), []byte(dark.String()), 0o644); err != nil {
39 panic(err)
40 }
41}