2018-04-02 06:49:54 +00:00
|
|
|
package helpers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
|
2022-05-26 10:17:10 +00:00
|
|
|
"github.com/alecthomas/chroma/v2/lexers"
|
2018-04-02 06:49:54 +00:00
|
|
|
"github.com/gohugoio/hugo/docshelper"
|
|
|
|
)
|
|
|
|
|
|
|
|
// This is is just some helpers used to create some JSON used in the Hugo docs.
|
|
|
|
func init() {
|
2020-03-20 15:34:53 +00:00
|
|
|
docsProvider := func() docshelper.DocProvider {
|
2022-03-17 21:03:27 +00:00
|
|
|
var chromaLexers []any
|
2018-04-02 06:49:54 +00:00
|
|
|
|
2022-05-26 10:17:10 +00:00
|
|
|
sort.Sort(lexers.GlobalLexerRegistry.Lexers)
|
2018-04-02 06:49:54 +00:00
|
|
|
|
2022-05-26 10:17:10 +00:00
|
|
|
for _, l := range lexers.GlobalLexerRegistry.Lexers {
|
2018-04-02 06:49:54 +00:00
|
|
|
|
|
|
|
config := l.Config()
|
|
|
|
|
|
|
|
lexerEntry := struct {
|
|
|
|
Name string
|
|
|
|
Aliases []string
|
|
|
|
}{
|
|
|
|
config.Name,
|
2022-05-26 10:17:10 +00:00
|
|
|
config.Aliases,
|
2018-04-02 06:49:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
chromaLexers = append(chromaLexers, lexerEntry)
|
|
|
|
|
|
|
|
}
|
2020-03-20 15:34:53 +00:00
|
|
|
|
2022-03-17 21:03:27 +00:00
|
|
|
return docshelper.DocProvider{"chroma": map[string]any{"lexers": chromaLexers}}
|
2018-04-02 06:49:54 +00:00
|
|
|
}
|
|
|
|
|
2020-03-20 15:34:53 +00:00
|
|
|
docshelper.AddDocProviderFunc(docsProvider)
|
2018-04-02 06:49:54 +00:00
|
|
|
}
|