Files
hugo/helpers/docshelper.go
T
Bjørn Erik Pedersen 790a8aa474
Test / test (1.26.x, ubuntu-latest) (push) Has been cancelled
Test / test (1.26.x, windows-latest) (push) Has been cancelled
deps: Add Chroma dark/light mode support
Closes #15017
2026-06-27 18:21:20 +02:00

64 lines
1.3 KiB
Go

package helpers
import (
"sort"
"github.com/alecthomas/chroma/v2/lexers"
"github.com/alecthomas/chroma/v2/styles"
"github.com/gohugoio/hugo/docshelper"
)
// This is just a helper used to create some JSON used in the Hugo docs.
func init() {
docsProvider := func() docshelper.DocProvider {
var chromaLexers []any
sort.Sort(lexers.GlobalLexerRegistry.Lexers)
for _, l := range lexers.GlobalLexerRegistry.Lexers {
config := l.Config()
lexerEntry := struct {
Name string
Aliases []string
}{
config.Name,
config.Aliases,
}
chromaLexers = append(chromaLexers, lexerEntry)
}
var styleInfos []styleInfo
for name := range styles.Registry {
style := styles.Registry[name]
styleInfos = append(styleInfos, styleInfo{
Name: name,
Counterpart: style.Counterpart,
Mode: style.Mode().String(),
})
}
sort.Slice(styleInfos, func(i, j int) bool {
return styleInfos[i].Name < styleInfos[j].Name
})
return docshelper.DocProvider{"chroma": map[string]any{
"lexers": chromaLexers,
"styles": styleInfos,
}}
}
docshelper.AddDocProviderFunc(docsProvider)
}
type styleInfo struct {
Name string `json:"name"`
Mode string `json:"mode"`
Counterpart string `json:"counterpart"`
}