Files
cheat/vendor/github.com/alecthomas/chroma/v2/lexers/lexers.go
Christopher Allen Lane 2a19755804 chore: modernize CI and update Go toolchain
- Bump Go from 1.19 to 1.26 and update all dependencies
- Rewrite CI workflow with matrix strategy (Linux, macOS, Windows)
- Update GitHub Actions to current versions (checkout@v4, setup-go@v5)
- Update CodeQL actions from v1 to v3
- Fix cross-platform bug in mock/path.go (path.Join -> filepath.Join)
- Clean up dependabot config (weekly schedule, remove stale ignore)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 20:58:51 -05:00

86 lines
2.2 KiB
Go

package lexers
import (
"embed"
"io/fs"
"github.com/alecthomas/chroma/v2"
)
//go:embed embedded
var embedded embed.FS
// GlobalLexerRegistry is the global LexerRegistry of Lexers.
var GlobalLexerRegistry = func() *chroma.LexerRegistry {
reg := chroma.NewLexerRegistry()
// index(reg)
paths, err := fs.Glob(embedded, "embedded/*.xml")
if err != nil {
panic(err)
}
for _, path := range paths {
reg.Register(chroma.MustNewXMLLexer(embedded, path))
}
return reg
}()
// Names of all lexers, optionally including aliases.
func Names(withAliases bool) []string {
return GlobalLexerRegistry.Names(withAliases)
}
// Aliases of all the lexers, and skip those lexers who do not have any aliases,
// or show their name instead
func Aliases(skipWithoutAliases bool) []string {
return GlobalLexerRegistry.Aliases(skipWithoutAliases)
}
// Get a Lexer by name, alias or file extension.
//
// Note that this if there isn't an exact match on name or alias, this will
// call Match(), so it is not efficient.
func Get(name string) chroma.Lexer {
return GlobalLexerRegistry.Get(name)
}
// MatchMimeType attempts to find a lexer for the given MIME type.
func MatchMimeType(mimeType string) chroma.Lexer {
return GlobalLexerRegistry.MatchMimeType(mimeType)
}
// Match returns the first lexer matching filename.
//
// Note that this iterates over all file patterns in all lexers, so it's not
// particularly efficient.
func Match(filename string) chroma.Lexer {
return GlobalLexerRegistry.Match(filename)
}
// Register a Lexer with the global registry.
func Register(lexer chroma.Lexer) chroma.Lexer {
return GlobalLexerRegistry.Register(lexer)
}
// Analyse text content and return the "best" lexer..
func Analyse(text string) chroma.Lexer {
return GlobalLexerRegistry.Analyse(text)
}
// PlaintextRules is used for the fallback lexer as well as the explicit
// plaintext lexer.
func PlaintextRules() chroma.Rules {
return chroma.Rules{
"root": []chroma.Rule{
{`.+`, chroma.Text, nil},
{`\n`, chroma.Text, nil},
},
}
}
// Fallback lexer if no other is found.
var Fallback chroma.Lexer = chroma.MustNewLexer(&chroma.Config{
Name: "fallback",
Filenames: []string{"*"},
Priority: -1,
}, PlaintextRules)