summaryrefslogtreecommitdiffstats
path: root/helpers/docshelper.go
blob: 5edbef11843989ed70f9b8f4a60f1ed3a8ab37f4 (plain) (blame)
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 helpers

import (
	"sort"

	"github.com/alecthomas/chroma/v2/lexers"
	"github.com/alecthomas/chroma/v2/styles"
	"github.com/gohugoio/hugo/docshelper"
)

// This is is just some helpers 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)

		}

		return docshelper.DocProvider{"chroma": map[string]any{
			"lexers": chromaLexers,
			"styles": styles.Names(),
		}}
	}

	docshelper.AddDocProviderFunc(docsProvider)
}