Skip to content

Commit

Permalink
docshelper: List Chroma lexers
Browse files Browse the repository at this point in the history
Fixes #4554
  • Loading branch information
bep committed Apr 2, 2018
1 parent eb15ac3 commit 2c54f1a
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions helpers/docshelper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package helpers

import (
"fmt"
"path/filepath"
"sort"
"strings"

"github.com/alecthomas/chroma/lexers"
"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() map[string]interface{} {
docs := make(map[string]interface{})

var chromaLexers []interface{}

sort.Sort(lexers.Registry.Lexers)

for _, l := range lexers.Registry.Lexers {

config := l.Config()

var filenames []string
filenames = append(filenames, config.Filenames...)
filenames = append(filenames, config.AliasFilenames...)

aliases := config.Aliases

for _, filename := range filenames {
alias := strings.TrimSpace(strings.TrimPrefix(filepath.Ext(filename), "."))
if alias != "" {
aliases = append(aliases, alias)
}
}

sort.Strings(aliases)
aliases = UniqueStrings(aliases)

lexerEntry := struct {
Name string
Aliases []string
}{
config.Name,
aliases,
}

chromaLexers = append(chromaLexers, lexerEntry)

docs["lexers"] = chromaLexers
}
return docs

}

docshelper.AddDocProvider("chroma", docsProvider)
}

0 comments on commit 2c54f1a

Please sign in to comment.