feat: HTML preview in PR/diff views — before/after iframes side-by-side

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-20 06:20:15 +01:00
parent a4314afc01
commit 3b91fcbaf4
5 changed files with 54 additions and 8 deletions
+3
View File
@@ -123,3 +123,6 @@ prime/
# A Makefile for custom make targets
Makefile.local
# Shared .tinqs sibling (Team Tool logs, sessions)
../.tinqs/
+9
View File
@@ -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)
+2 -1
View File
@@ -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
+4 -1
View File
@@ -78,7 +78,8 @@
{{$sniffedTypeHead := call $.GetSniffedTypeForBlob $blobHead}}
{{$isImage:= or (call $.IsSniffedTypeAnImage $sniffedTypeBase) (call $.IsSniffedTypeAnImage $sniffedTypeHead)}}
{{$isCsv := (call $.IsCsvFile $file)}}
{{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}}
{{$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}}
<div class="diff-file-box file-content {{TabSizeClass $.Editorconfig $file.Name}} tw-mt-0" id="diff-{{$file.NameHash}}" data-old-filename="{{$file.OldName}}" data-new-filename="{{$file.Name}}" {{if or ($file.ShouldBeHidden) (not $isExpandable)}}data-folded="true"{{end}}>
@@ -199,6 +200,8 @@
<table class="chroma tw-w-full">
{{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}}
+30
View File
@@ -0,0 +1,30 @@
{{if or .blobBase .blobHead}}
<tr>
<td colspan="2">
<div class="ui bottom attached segment tw-p-2">
<div class="tw-grid tw-grid-cols-2 tw-gap-4">
{{if .blobBase}}
<div>
<div class="ui top attached header tw-font-normal tw-mb-1">{{ctx.Locale.Tr "repo.diff.file_before"}}</div>
<iframe
src="{{.root.BeforeRawPath}}/{{PathEscapeSegments .file.OldName}}"
style="width:100%;min-height:400px;border:1px solid var(--color-secondary);"
sandbox="allow-scripts allow-same-origin"
></iframe>
</div>
{{end}}
{{if .blobHead}}
<div{{if and .blobBase .blobHead}} class="tw-col-start-2"{{end}}>
<div class="ui top attached header tw-font-normal tw-mb-1">{{ctx.Locale.Tr "repo.diff.file_after"}}</div>
<iframe
src="{{.root.RawPath}}/{{PathEscapeSegments .file.Name}}"
style="width:100%;min-height:400px;border:1px solid var(--color-secondary);"
sandbox="allow-scripts allow-same-origin"
></iframe>
</div>
{{end}}
</div>
</div>
</td>
</tr>
{{end}}