diff options
author | Dustin Firebaugh <dafirebaugh@gmail.com> | 2025-03-08 23:51:58 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-09 12:51:58 +0800 |
commit | 3f1f808b9eeb3f7cd923c6b89fbb57583202e76d (patch) | |
tree | 1eb4364b04aa43657f6846e5ee94c8bd7a405b1d /modules/highlight | |
parent | 6f1333175461a6cf5497965c20b5d81b6e73c5d5 (diff) | |
download | gitea-3f1f808b9eeb3f7cd923c6b89fbb57583202e76d.tar.gz gitea-3f1f808b9eeb3f7cd923c6b89fbb57583202e76d.zip |
Full-file syntax highlighting for diff pages (#33766)
Fix #33358, fix #21970
This adds a step in the `GitDiffForRender` that does syntax highlighting for the
entire file and then only references lines from that syntax highlighted
code. This allows things like multi-line comments to be syntax
highlighted correctly.
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules/highlight')
-rw-r--r-- | modules/highlight/highlight.go | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/modules/highlight/highlight.go b/modules/highlight/highlight.go index d7ab3f7afd..77f24fa3f3 100644 --- a/modules/highlight/highlight.go +++ b/modules/highlight/highlight.go @@ -11,6 +11,7 @@ import ( gohtml "html" "html/template" "io" + "path" "path/filepath" "strings" "sync" @@ -83,7 +84,7 @@ func Code(fileName, language, code string) (output template.HTML, lexerName stri } if lexer == nil { - if val, ok := highlightMapping[filepath.Ext(fileName)]; ok { + if val, ok := highlightMapping[path.Ext(fileName)]; ok { // use mapped value to find lexer lexer = lexers.Get(val) } |