mirror of
https://github.com/alecthomas/chroma.git
synced 2025-01-28 03:29:41 +02:00
Add lexers.MatchMimeType(mimeType).
This commit is contained in:
parent
d80c30ae4e
commit
00d5486e6b
@ -115,9 +115,15 @@ func listAll() {
|
||||
filenames := []string{}
|
||||
filenames = append(filenames, config.Filenames...)
|
||||
filenames = append(filenames, config.AliasFilenames...)
|
||||
fmt.Printf(" aliases: %s\n", strings.Join(config.Aliases, " "))
|
||||
fmt.Printf(" filenames: %s\n", strings.Join(filenames, " "))
|
||||
fmt.Printf(" mimetypes: %s\n", strings.Join(config.MimeTypes, " "))
|
||||
if len(config.Aliases) > 0 {
|
||||
fmt.Printf(" aliases: %s\n", strings.Join(config.Aliases, " "))
|
||||
}
|
||||
if len(filenames) > 0 {
|
||||
fmt.Printf(" filenames: %s\n", strings.Join(filenames, " "))
|
||||
}
|
||||
if len(config.MimeTypes) > 0 {
|
||||
fmt.Printf(" mimetypes: %s\n", strings.Join(config.MimeTypes, " "))
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Printf("styles:")
|
||||
|
@ -40,7 +40,19 @@ func Get(name string) chroma.Lexer {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Match returns all lexers matching filename.
|
||||
// MatchMimeType attempts to find a lexer for the given MIME type.
|
||||
func MatchMimeType(mimeType string) chroma.Lexer {
|
||||
for _, l := range Registry.Lexers {
|
||||
for _, lmt := range l.Config().MimeTypes {
|
||||
if mimeType == lmt {
|
||||
return l
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Match returns the first lexer matching filename.
|
||||
func Match(filename string) chroma.Lexer {
|
||||
filename = filepath.Base(filename)
|
||||
for _, lexer := range Registry.Lexers {
|
||||
|
Loading…
x
Reference in New Issue
Block a user