feat: HTML file preview — render .html as pages, not source (Phase 1.1)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -153,6 +153,19 @@ func handleFileViewRenderImage(ctx *context.Context, fInfo *fileInfo, prefetchBu
|
||||
return true
|
||||
}
|
||||
|
||||
func handleFileViewRenderHTML(ctx *context.Context, fInfo *fileInfo) bool {
|
||||
if !strings.HasSuffix(strings.ToLower(ctx.Repo.TreePath), ".html") {
|
||||
return false
|
||||
}
|
||||
// Allow toggling to source view
|
||||
if ctx.FormString("display") == "source" {
|
||||
return false
|
||||
}
|
||||
ctx.Data["IsHTMLFile"] = true
|
||||
ctx.Data["HasSourceRenderedToggle"] = true
|
||||
return true
|
||||
}
|
||||
|
||||
func prepareFileView(ctx *context.Context, entry *git.TreeEntry) {
|
||||
ctx.Data["IsViewFile"] = true
|
||||
ctx.Data["HideRepoInfo"] = true
|
||||
@@ -239,6 +252,7 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) {
|
||||
case fInfo.blobOrLfsSize >= setting.UI.MaxDisplayFileSize:
|
||||
ctx.Data["IsFileTooLarge"] = true
|
||||
case handleFileViewRenderMarkup(ctx, buf, contentReader):
|
||||
case handleFileViewRenderHTML(ctx, fInfo):
|
||||
case handleFileViewRenderSource(ctx, attrs, fInfo, contentReader):
|
||||
// it also sets ctx.Data["FileContent"] and more
|
||||
ctx.Data["IsDisplayingSource"] = true
|
||||
|
||||
@@ -125,11 +125,13 @@
|
||||
<video controls src="{{$.RawFileLink}}">
|
||||
<strong>{{ctx.Locale.Tr "repo.video_not_supported_in_browser"}}</strong>
|
||||
</video>
|
||||
{{else if .IsAudioFile}}
|
||||
<audio controls src="{{$.RawFileLink}}">
|
||||
<strong>{{ctx.Locale.Tr "repo.audio_not_supported_in_browser"}}</strong>
|
||||
</audio>
|
||||
{{else}}
|
||||
{{else if .IsAudioFile}}
|
||||
<audio controls src="{{$.RawFileLink}}">
|
||||
<strong>{{ctx.Locale.Tr "repo.audio_not_supported_in_browser"}}</strong>
|
||||
</audio>
|
||||
{{else if .IsHTMLFile}}
|
||||
<iframe src="{{$.RawFileLink}}" class="html-preview-iframe" style="width:100%;min-height:600px;border:none;" sandbox="allow-scripts allow-same-origin"></iframe>
|
||||
{{else}}
|
||||
<div class="file-view-render-container">
|
||||
<div class="file-view-raw-prompt tw-p-4">
|
||||
<a href="{{$.RawFileLink}}" rel="nofollow">{{ctx.Locale.Tr "repo.file_view_raw"}}</a>
|
||||
|
||||
Reference in New Issue
Block a user