docshelper: List Chroma lexers - hugo - [fork] hugo port for 9front
 (HTM) git clone git@git.drkhsh.at/hugo.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 2c54f1ad48fe2a2f7504117d351d45abc89dcb1f
 (DIR) parent eb15ac37ef6668e298c0c4d8062726cd545da576
 (HTM) Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Mon,  2 Apr 2018 08:49:54 +0200
       
       docshelper: List Chroma lexers
       
       Fixes #4554
       
       Diffstat:
         A helpers/docshelper.go               |      60 +++++++++++++++++++++++++++++++
       
       1 file changed, 60 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/helpers/docshelper.go b/helpers/docshelper.go
       @@ -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)
       +}