package lexers
import (
"embed"
"io/fs"
"github.com/alecthomas/chroma/v2"
)
var embedded embed .FS
var GlobalLexerRegistry = func () *chroma .LexerRegistry {
reg := chroma .NewLexerRegistry ()
paths , err := fs .Glob (embedded , "embedded/*.xml" )
if err != nil {
panic (err )
}
for _ , path := range paths {
reg .Register (chroma .MustNewXMLLexer (embedded , path ))
}
return reg
}()
func Names (withAliases bool ) []string {
return GlobalLexerRegistry .Names (withAliases )
}
func Get (name string ) chroma .Lexer {
return GlobalLexerRegistry .Get (name )
}
func MatchMimeType (mimeType string ) chroma .Lexer {
return GlobalLexerRegistry .MatchMimeType (mimeType )
}
func Match (filename string ) chroma .Lexer {
return GlobalLexerRegistry .Match (filename )
}
func Register (lexer chroma .Lexer ) chroma .Lexer {
return GlobalLexerRegistry .Register (lexer )
}
func Analyse (text string ) chroma .Lexer {
return GlobalLexerRegistry .Analyse (text )
}
func PlaintextRules () chroma .Rules {
return chroma .Rules {
"root" : []chroma .Rule {
{`.+` , chroma .Text , nil },
{`\n` , chroma .Text , nil },
},
}
}
var Fallback chroma .Lexer = chroma .MustNewLexer (&chroma .Config {
Name : "fallback" ,
Filenames : []string {"*" },
Priority : -1 ,
}, PlaintextRules )
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .