Skip to content

Conversation

@wxiaoguang
Copy link
Contributor

No description provided.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 10, 2025
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Mar 10, 2025
@wxiaoguang
Copy link
Contributor Author

Before:

  • Some files like "php" were not recognized by the material icon rules.
  • The full-file diff highlight is not quite right

After:

image

image

image

image

@wxiaoguang wxiaoguang added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Mar 10, 2025
@wxiaoguang wxiaoguang added this to the 1.24.0 milestone Mar 10, 2025
@wxiaoguang wxiaoguang force-pushed the fix-icon-highlight branch 2 times, most recently from f3a1752 to 4697a79 Compare March 10, 2025 12:49
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 10, 2025
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 10, 2025
@wxiaoguang wxiaoguang merged commit 657239b into go-gitea:main Mar 10, 2025
26 checks passed
@wxiaoguang wxiaoguang deleted the fix-icon-highlight branch March 10, 2025 14:35
hiifong pushed a commit to hiifong/gitea that referenced this pull request Mar 10, 2025
@wxiaoguang
Copy link
Contributor Author

Next: Fix file icon mapping #33855

zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 12, 2025
* giteaofficial/main:
  Fix various Fomantic UI and htmx problems (go-gitea#33851)
  Add workflow_job webhook (go-gitea#33694)
  Fix file icon mapping (go-gitea#33855)
  Drop fomantic build (go-gitea#33845)
  Fix auto concurrency cancellation skips commit status updates (go-gitea#33764)
  Fix test code (go-gitea#33829)
  Remove "noscript" tag from html head (go-gitea#33846)
  Fix material icon & diff highlight (go-gitea#33844)
  Fix LFS URL (go-gitea#33840)
  Add material icons for file list (go-gitea#33837)
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jun 8, 2025
@lunny
Copy link
Member

lunny commented Dec 13, 2025

There is a regression caused #35504

@wxiaoguang
Copy link
Contributor Author

There is a regression caused #35504

The regression is from this PR, or indeed from " Full-file syntax highlighting for diff pages #33766 "?

@lunny
Copy link
Member

lunny commented Dec 13, 2025

There is a regression caused #35504

The regression is from this PR, or indeed from " Full-file syntax highlighting for diff pages #33766 "?

I used git bisect to identify the issue, and it points to this PR. When I check out commit 657239b, I can reproduce the bug. However, checking out the previous commit, c102492, everything works correctly.

@wxiaoguang
Copy link
Contributor Author

diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 6e15f71609..1a82c7fb7f 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -1337,6 +1337,7 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit
 }
 
 func highlightCodeLines(diffFile *DiffFile, isLeft bool, content string) map[int]template.HTML {
+       content, _ = charset.ToUTF8(util.UnsafeStringToBytes(content), charset.ConvertOpts{KeepBOM: false})
        highlightedNewContent, _ := highlight.Code(diffFile.Name, diffFile.Language, content)
        splitLines := strings.Split(string(highlightedNewContent), "\n")
        lines := make(map[int]template.HTML, len(splitLines))

Can you try this?

@lunny
Copy link
Member

lunny commented Dec 13, 2025

diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 6e15f71609..1a82c7fb7f 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -1337,6 +1337,7 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit
 }
 
 func highlightCodeLines(diffFile *DiffFile, isLeft bool, content string) map[int]template.HTML {
+       content, _ = charset.ToUTF8(util.UnsafeStringToBytes(content), charset.ConvertOpts{KeepBOM: false})
        highlightedNewContent, _ := highlight.Code(diffFile.Name, diffFile.Language, content)
        splitLines := strings.Split(string(highlightedNewContent), "\n")
        lines := make(map[int]template.HTML, len(splitLines))

Can you try this?

Looks like it works

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants