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:
@@ -123,3 +123,6 @@ prime/
|
||||
|
||||
# A Makefile for custom make targets
|
||||
Makefile.local
|
||||
|
||||
# Shared .tinqs sibling (Team Tool logs, sessions)
|
||||
../.tinqs/
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}}
|
||||
<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}}>
|
||||
@@ -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" */}}
|
||||
<div id="diff-rendered-{{$file.NameHash}}" class="file-body file-code {{if $.IsSplitStyle}}code-diff-split{{else}}code-diff-unified{{end}} tw-overflow-x-scroll">
|
||||
<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}}
|
||||
{{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}}
|
||||
</table>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
@@ -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}}
|
||||
Reference in New Issue
Block a user