diff options
author | mrsdizzie <info@mrsdizzie.com> | 2020-11-13 16:13:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-13 16:13:41 -0500 |
commit | 6280af03240b13f66a54e7c91d913ce98c3887eb (patch) | |
tree | b25f87766e2e125d894e4837a8ae7ecad612b10a /modules/highlight | |
parent | 3cd00c33cebf5651f2fdbc356783d1be0733ac71 (diff) | |
download | gitea-6280af03240b13f66a54e7c91d913ce98c3887eb.tar.gz gitea-6280af03240b13f66a54e7c91d913ce98c3887eb.zip |
Use existing analyzer module for language detection for highlighting (#13522)
* Use existing analyzer module for language detction for highlighting
Thanks @lafriks for pointing out we can reuse existing code for more reliable language detection here.
* Update modules/highlight/highlight.go
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules/highlight')
-rw-r--r-- | modules/highlight/highlight.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/modules/highlight/highlight.go b/modules/highlight/highlight.go index 1a64108139..914ba8210e 100644 --- a/modules/highlight/highlight.go +++ b/modules/highlight/highlight.go @@ -13,6 +13,7 @@ import ( "strings" "sync" + "code.gitea.io/gitea/modules/analyze" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "github.com/alecthomas/chroma/formatters/html" @@ -117,9 +118,11 @@ func File(numLines int, fileName string, code []byte) map[int]string { fileName = "test." + val } - lexer := lexers.Match(fileName) + language := analyze.GetCodeLanguage(fileName, code) + + lexer := lexers.Get(language) if lexer == nil { - lexer = lexers.Analyse(string(code)) + lexer = lexers.Match(fileName) if lexer == nil { lexer = lexers.Fallback } |