mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 19:06:18 +01:00 
			
		
		
		
	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>
This commit is contained in:
		| @@ -5,30 +5,33 @@ package integration | ||||
|  | ||||
| import ( | ||||
| 	"net/http" | ||||
| 	"net/url" | ||||
| 	"testing" | ||||
|  | ||||
| 	pull_service "code.gitea.io/gitea/services/pull" | ||||
|  | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| 	"github.com/stretchr/testify/require" | ||||
| ) | ||||
|  | ||||
| func TestListPullCommits(t *testing.T) { | ||||
| 	onGiteaRun(t, func(t *testing.T, u *url.URL) { | ||||
| 		session := loginUser(t, "user5") | ||||
| 		req := NewRequest(t, "GET", "/user2/repo1/pulls/3/commits/list") | ||||
| 		resp := session.MakeRequest(t, req, http.StatusOK) | ||||
| 	session := loginUser(t, "user5") | ||||
| 	req := NewRequest(t, "GET", "/user2/repo1/pulls/3/commits/list") | ||||
| 	resp := session.MakeRequest(t, req, http.StatusOK) | ||||
|  | ||||
| 		var pullCommitList struct { | ||||
| 			Commits             []pull_service.CommitInfo `json:"commits"` | ||||
| 			LastReviewCommitSha string                    `json:"last_review_commit_sha"` | ||||
| 		} | ||||
| 		DecodeJSON(t, resp, &pullCommitList) | ||||
| 	var pullCommitList struct { | ||||
| 		Commits             []pull_service.CommitInfo `json:"commits"` | ||||
| 		LastReviewCommitSha string                    `json:"last_review_commit_sha"` | ||||
| 	} | ||||
| 	DecodeJSON(t, resp, &pullCommitList) | ||||
|  | ||||
| 		if assert.Len(t, pullCommitList.Commits, 2) { | ||||
| 			assert.Equal(t, "985f0301dba5e7b34be866819cd15ad3d8f508ee", pullCommitList.Commits[0].ID) | ||||
| 			assert.Equal(t, "5c050d3b6d2db231ab1f64e324f1b6b9a0b181c2", pullCommitList.Commits[1].ID) | ||||
| 		} | ||||
| 		assert.Equal(t, "4a357436d925b5c974181ff12a994538ddc5a269", pullCommitList.LastReviewCommitSha) | ||||
| 	require.Len(t, pullCommitList.Commits, 2) | ||||
| 	assert.Equal(t, "985f0301dba5e7b34be866819cd15ad3d8f508ee", pullCommitList.Commits[0].ID) | ||||
| 	assert.Equal(t, "5c050d3b6d2db231ab1f64e324f1b6b9a0b181c2", pullCommitList.Commits[1].ID) | ||||
| 	assert.Equal(t, "4a357436d925b5c974181ff12a994538ddc5a269", pullCommitList.LastReviewCommitSha) | ||||
|  | ||||
| 	t.Run("CommitBlobExcerpt", func(t *testing.T) { | ||||
| 		req = NewRequest(t, "GET", "/user2/repo1/blob_excerpt/985f0301dba5e7b34be866819cd15ad3d8f508ee?last_left=0&last_right=0&left=2&right=2&left_hunk_size=2&right_hunk_size=2&path=README.md&style=split&direction=up") | ||||
| 		resp = session.MakeRequest(t, req, http.StatusOK) | ||||
| 		assert.Contains(t, resp.Body.String(), `<td class="lines-code lines-code-new"><code class="code-inner"># repo1</code>`) | ||||
| 	}) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user