diff --git a/modules/highlight/highlight_test.go b/modules/highlight/highlight_test.go index 211132b255f..a31f8752f15 100644 --- a/modules/highlight/highlight_test.go +++ b/modules/highlight/highlight_test.go @@ -63,7 +63,7 @@ func TestFile(t *testing.T) { { name: "tags.py", code: "<>", - want: lines(`<>`), + want: lines(`<>`), lexerName: "Python", }, { @@ -102,7 +102,7 @@ c=2 def:\n a=1\n \n -b=''\n +b=''\n \n c=2`, ), @@ -114,6 +114,18 @@ c=2 want: []template.HTML{"--\n", `SELECT`}, lexerName: "SQL", }, + { + name: "test.http", + code: `HTTP/1.0 400 Bad request +Content-Type: text/html + +`, + want: lines(`HTTP/1.0 400 Bad request\n +Content-Type: text/html\n +\n +<html></html>`), + lexerName: "HTTP", + }, } for _, tt := range tests { diff --git a/modules/highlight/lexerdetect.go b/modules/highlight/lexerdetect.go index 5b3348761c2..06835f2898a 100644 --- a/modules/highlight/lexerdetect.go +++ b/modules/highlight/lexerdetect.go @@ -289,24 +289,24 @@ func detectChromaLexerWithAnalyze(fileName, lang string, code []byte) chroma.Lex // if lang is provided, and it matches a lexer, use it directly if byLang { - return lexer + return chroma.Coalesce(lexer) } // if a lexer is detected and there is no conflict for the file extension, use it directly fileExt := path.Ext(fileName) _, hasConflicts := chromaLexers().conflictingExtLangMap[fileExt] if !hasConflicts && lexer != lexers.Fallback { - return lexer + return chroma.Coalesce(lexer) } // try to detect language by content, for best guessing for the language // when using "code" to detect, analyze.GetCodeLanguage is slow, it iterates many rules to detect language from content analyzedLanguage := analyze.GetCodeLanguage(fileName, code) - lexer = DetectChromaLexerByFileName(fileName, analyzedLanguage) + lexer, _ = detectChromaLexerByFileName(fileName, analyzedLanguage) if lexer == lexers.Fallback { if analyzedLanguage != enry.OtherLanguage { log.Warn("No chroma lexer found for enry detected language: %s (file: %s), need to fix the language mapping between enry and chroma.", analyzedLanguage, fileName) } } - return lexer + return chroma.Coalesce(lexer) }