0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 07:13:02 -05:00

[BUG] Make chroma match case-insenstive

- In the case that [go-enry](https://github.com/go-enry/go-enry/)
returned langauge doesn't match a lexer name (Either because its not
available or because it doesn't match Chroma's name), a last effort
attempt is made to use Chroma's matching.
- go-enry already applies `strings.ToLower` onto the filename to avoid
being case-sensitive, add the same code for Chroma's matching. The code
being used doesn't rely on the filename being case senstive for correct
matching.
- Adds unit test.
- Resolves #752
This commit is contained in:
Gusted 2024-10-11 15:26:02 +02:00
parent 4cb01ba5da
commit dcc442351d
No known key found for this signature in database
GPG key ID: FD821B732837125F
2 changed files with 8 additions and 2 deletions

View file

@ -96,7 +96,7 @@ func Code(fileName, language, code string) (output template.HTML, lexerName stri
}
if lexer == nil {
lexer = lexers.Match(fileName)
lexer = lexers.Match(strings.ToLower(fileName))
if lexer == nil {
lexer = lexers.Fallback
}
@ -165,7 +165,7 @@ func File(fileName, language string, code []byte) ([]template.HTML, string, erro
lexer = lexers.Get(guessLanguage)
if lexer == nil {
lexer = lexers.Match(fileName)
lexer = lexers.Match(strings.ToLower(fileName))
if lexer == nil {
lexer = lexers.Fallback
}

View file

@ -109,6 +109,12 @@ c=2
),
lexerName: "Python",
},
{
name: "DOS.PAS",
code: "",
want: lines(""),
lexerName: "ObjectPascal",
},
}
for _, tt := range tests {