1
0
Fork 0
forked from forgejo/forgejo

Update chroma (#18033)

Update chroma to 0.9.4

Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
zeripath 2021-12-20 02:49:38 +00:00 committed by GitHub
parent fb5f7791ef
commit 25677cdc5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 937 additions and 683 deletions

View file

@ -6,8 +6,6 @@ import (
"sort"
"strings"
"github.com/danwakefield/fnmatch"
"github.com/alecthomas/chroma"
)
@ -15,8 +13,8 @@ var (
ignoredSuffixes = [...]string{
// Editor backups
"~", ".bak", ".old", ".orig",
// Debian and derivatives apt/dpkg backups
".dpkg-dist", ".dpkg-old",
// Debian and derivatives apt/dpkg/ucf backups
".dpkg-dist", ".dpkg-old", ".ucf-dist", ".ucf-new", ".ucf-old",
// Red Hat and derivatives rpm backups
".rpmnew", ".rpmorig", ".rpmsave",
// Build system input/template files
@ -104,11 +102,17 @@ func Match(filename string) chroma.Lexer {
for _, lexer := range Registry.Lexers {
config := lexer.Config()
for _, glob := range config.Filenames {
if fnmatch.Match(glob, filename, 0) {
ok, err := filepath.Match(glob, filename)
if err != nil { // nolint
panic(err)
} else if ok {
matched = append(matched, lexer)
} else {
for _, suf := range &ignoredSuffixes {
if fnmatch.Match(glob+suf, filename, 0) {
ok, err := filepath.Match(glob+suf, filename)
if err != nil {
panic(err)
} else if ok {
matched = append(matched, lexer)
break
}
@ -125,11 +129,17 @@ func Match(filename string) chroma.Lexer {
for _, lexer := range Registry.Lexers {
config := lexer.Config()
for _, glob := range config.AliasFilenames {
if fnmatch.Match(glob, filename, 0) {
ok, err := filepath.Match(glob, filename)
if err != nil { // nolint
panic(err)
} else if ok {
matched = append(matched, lexer)
} else {
for _, suf := range &ignoredSuffixes {
if fnmatch.Match(glob+suf, filename, 0) {
ok, err := filepath.Match(glob+suf, filename)
if err != nil {
panic(err)
} else if ok {
matched = append(matched, lexer)
break
}