summaryrefslogtreecommitdiff
path: root/vendor/github.com/alecthomas/chroma/v2/lexers/lexers.go
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2024-10-25 00:47:47 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2024-10-25 00:47:47 +0200
commitc6cc0108ca7738023b45e0eeac0fa2390532dd93 (patch)
tree36890e6cd3091bbab8efbe686cc56f467f645bfd /vendor/github.com/alecthomas/chroma/v2/lexers/lexers.go
parent0130404a1dc663d4aa68d780c9bcb23a4243e68d (diff)
downloadjbmafp-master.tar.gz
Added vendor lock on depsHEADmaster
Diffstat (limited to 'vendor/github.com/alecthomas/chroma/v2/lexers/lexers.go')
-rw-r--r--vendor/github.com/alecthomas/chroma/v2/lexers/lexers.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/vendor/github.com/alecthomas/chroma/v2/lexers/lexers.go b/vendor/github.com/alecthomas/chroma/v2/lexers/lexers.go
new file mode 100644
index 0000000..161caef
--- /dev/null
+++ b/vendor/github.com/alecthomas/chroma/v2/lexers/lexers.go
@@ -0,0 +1,73 @@
+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)
+}
+
+// Get a Lexer by name, alias or file extension.
+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.
+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)