/
githubmirror
/
hugo
Обзор
Документация
Войти
/
githubmirror
/
hugo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
helpers/docshelper.go
63 строки
1 KB
Bjørn Erik Pedersen
deps: Add Chroma dark/light mode support
27 июн 2026, 19:21
27 июн 2026, 19:21
790a8aa
Код
Авторство
О чём код?
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"` }