From dcc442351d2a70344dba582ec76c14a39e5aa2c0 Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 11 Oct 2024 15:26:02 +0200 Subject: [PATCH] [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 --- modules/highlight/highlight.go | 4 ++-- modules/highlight/highlight_test.go | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/highlight/highlight.go b/modules/highlight/highlight.go index 4ee47b7a13..bd6137dc85 100644 --- a/modules/highlight/highlight.go +++ b/modules/highlight/highlight.go @@ -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 } diff --git a/modules/highlight/highlight_test.go b/modules/highlight/highlight_test.go index 83d35d93ef..03db4d5090 100644 --- a/modules/highlight/highlight_test.go +++ b/modules/highlight/highlight_test.go @@ -109,6 +109,12 @@ c=2 ), lexerName: "Python", }, + { + name: "DOS.PAS", + code: "", + want: lines(""), + lexerName: "ObjectPascal", + }, } for _, tt := range tests {