mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-30 22:06:11 +01:00
Merge pull request 'fix: normalize guessed languages from enry' (#6084) from gusted/forgejo-f#-or-fsharp into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6084 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
bd2593a771
|
@ -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 {
|
||||
|
|
|
@ -115,6 +115,12 @@ c=2
|
|||
want: lines(""),
|
||||
lexerName: "ObjectPascal",
|
||||
},
|
||||
{
|
||||
name: "test.fs",
|
||||
code: "module Crypt = let generateCryptTable: array<uint32> =",
|
||||
want: lines(`<span class="k">module</span> <span class="nn">Crypt</span> <span class="o">=</span> <span class="k">let</span> <span class="nv">generateCryptTable</span><span class="o">:</span> <span class="n">array</span><span class="o"><</span><span class="kt">uint32</span><span class="o">></span> <span class="o">=</span>`),
|
||||
lexerName: "FSharp",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
Loading…
Reference in a new issue