From 3b91fcbaf43855e54557af007d8faa07a812e8a8 Mon Sep 17 00:00:00 2001 From: tinqs-limited Date: Wed, 20 May 2026 06:20:15 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20HTML=20preview=20in=20PR/diff=20views?= =?UTF-8?q?=20=E2=80=94=20before/after=20iframes=20side-by-side?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .gitignore | 3 +++ routers/web/repo/compare.go | 9 +++++++++ routers/web/repo/view_file.go | 3 ++- templates/repo/diff/box.tmpl | 17 ++++++++++------- templates/repo/diff/html_diff.tmpl | 30 ++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 templates/repo/diff/html_diff.tmpl diff --git a/.gitignore b/.gitignore index 0ac6ed9dfa..ddca4a0495 100644 --- a/.gitignore +++ b/.gitignore @@ -123,3 +123,6 @@ prime/ # A Makefile for custom make targets Makefile.local + +# Shared .tinqs sibling (Team Tool logs, sessions) +../.tinqs/ diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 285f3968d4..f2c3e60bc2 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -82,6 +82,15 @@ func setCompareContext(ctx *context.Context, before, head *git.Commit, headOwner return st } + ctx.Data["IsHTMLFile"] = func(diffFile *gitdiff.DiffFile) bool { + extension := strings.ToLower(filepath.Ext(diffFile.Name)) + if extension == ".html" || extension == ".htm" { + return true + } + extension = strings.ToLower(filepath.Ext(diffFile.OldName)) + return extension == ".html" || extension == ".htm" + } + setPathsCompareContext(ctx, before, head, headOwner, headName) setImageCompareContext(ctx) setCsvCompareContext(ctx) diff --git a/routers/web/repo/view_file.go b/routers/web/repo/view_file.go index d7a0b3174c..7c37f249fb 100644 --- a/routers/web/repo/view_file.go +++ b/routers/web/repo/view_file.go @@ -154,7 +154,8 @@ func handleFileViewRenderImage(ctx *context.Context, fInfo *fileInfo, prefetchBu } func handleFileViewRenderHTML(ctx *context.Context, fInfo *fileInfo) bool { - if !strings.HasSuffix(strings.ToLower(ctx.Repo.TreePath), ".html") { + lower := strings.ToLower(ctx.Repo.TreePath) + if !strings.HasSuffix(lower, ".html") && !strings.HasSuffix(lower, ".htm") { return false } // Allow toggling to source view diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 390e41ec34..a37d35036f 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -77,8 +77,9 @@ {{$sniffedTypeBase := call $.GetSniffedTypeForBlob $blobBase}} {{$sniffedTypeHead := call $.GetSniffedTypeForBlob $blobHead}} {{$isImage:= or (call $.IsSniffedTypeAnImage $sniffedTypeBase) (call $.IsSniffedTypeAnImage $sniffedTypeHead)}} - {{$isCsv := (call $.IsCsvFile $file)}} - {{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}} + {{$isCsv := (call $.IsCsvFile $file)}} + {{$isHTML := (call $.IsHTMLFile $file)}} + {{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv) $isHTML}} {{$isExpandable := or (gt $file.Addition 0) (gt $file.Deletion 0) $file.IsBin}} {{$isReviewFile := and $.IsSigned $.PageIsPullFiles (not $.Repository.IsArchived) $.IsShowingAllCommits}}
@@ -197,11 +198,13 @@ {{/* for image or CSV, it can have a horizontal scroll bar, there won't be review comment context menu (position absolute) which would be clipped by "overflow" */}}
- {{if $isImage}} - {{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}} - {{else}} - {{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}} - {{end}} + {{if $isImage}} + {{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}} + {{else if $isHTML}} + {{template "repo/diff/html_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}} + {{else}} + {{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}} + {{end}}
{{end}} diff --git a/templates/repo/diff/html_diff.tmpl b/templates/repo/diff/html_diff.tmpl new file mode 100644 index 0000000000..1ec20eb5ef --- /dev/null +++ b/templates/repo/diff/html_diff.tmpl @@ -0,0 +1,30 @@ +{{if or .blobBase .blobHead}} + + +
+
+ {{if .blobBase}} +
+
{{ctx.Locale.Tr "repo.diff.file_before"}}
+ +
+ {{end}} + {{if .blobHead}} + +
{{ctx.Locale.Tr "repo.diff.file_after"}}
+ +
+ {{end}} +
+
+ + +{{end}}