diff --git a/modules/highlight/highlight.go b/modules/highlight/highlight.go index bd6137dc85..243aa2b566 100644 --- a/modules/highlight/highlight.go +++ b/modules/highlight/highlight.go @@ -134,6 +134,12 @@ func CodeFromLexer(lexer chroma.Lexer, code string) template.HTML { return template.HTML(strings.TrimSuffix(htmlbuf.String(), "\n")) } +// For the case where Enry recognizes the language, but doesn't use the naming +// that Chroma expects. +var normalizeEnryToChroma = map[string]string{ + "F#": "FSharp", +} + // File returns a slice of chroma syntax highlighted HTML lines of code and the matched lexer name func File(fileName, language string, code []byte) ([]template.HTML, string, error) { NewContext() @@ -162,6 +168,9 @@ func File(fileName, language string, code []byte) ([]template.HTML, string, erro if lexer == nil { guessLanguage := analyze.GetCodeLanguage(fileName, code) + if normalizedGuessLanguage, ok := normalizeEnryToChroma[guessLanguage]; ok { + guessLanguage = normalizedGuessLanguage + } lexer = lexers.Get(guessLanguage) if lexer == nil { diff --git a/modules/highlight/highlight_test.go b/modules/highlight/highlight_test.go index 03db4d5090..0127854c8e 100644 --- a/modules/highlight/highlight_test.go +++ b/modules/highlight/highlight_test.go @@ -115,6 +115,12 @@ c=2 want: lines(""), lexerName: "ObjectPascal", }, + { + name: "test.fs", + code: "module Crypt = let generateCryptTable: array =", + want: lines(`module Crypt = let generateCryptTable: array<uint32> =`), + lexerName: "FSharp", + }, } for _, tt := range tests {