summaryrefslogtreecommitdiff
path: root/cmd/css/main.go
blob: 367e1b8fa43623e6232a4374ac4d605849f3a3b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main

import (
	"os"
	"path/filepath"
	"runtime"
	"strings"

	"github.com/alecthomas/chroma/v2/formatters/html"
	"github.com/alecthomas/chroma/v2/styles"
)

func main() {
	_, file, _, _ := runtime.Caller(0)
	cssDir := filepath.Join(filepath.Dir(file), "../../internal/templates/css")

	formatter := html.New(
		html.WithLineNumbers(true),
		html.WithLinkableLineNumbers(true, "L"),
		html.WithClasses(true),
	)

	lightStyle := styles.Get("github")
	darkStyle := styles.Get("github-dark")

	var light, dark strings.Builder
	_ = formatter.WriteCSS(&light, lightStyle)
	_ = formatter.WriteCSS(&dark, darkStyle)

	light.WriteString(".chroma .gi { display: block; }\n")
	light.WriteString(".chroma .gd { display: block; }\n")
	dark.WriteString(".chroma .gi { display: block; }\n")
	dark.WriteString(".chroma .gd { display: block; }\n")

	if err := os.WriteFile(filepath.Join(cssDir, "syntax_light.css"), []byte(light.String()), 0o644); err != nil {
		panic(err)
	}
	if err := os.WriteFile(filepath.Join(cssDir, "syntax_dark.css"), []byte(dark.String()), 0o644); err != nil {
		panic(err)
	}
}