From a4314afc010824bfd8f904e197dd253eac33ef84 Mon Sep 17 00:00:00 2001 From: tinqs-limited Date: Wed, 20 May 2026 06:06:29 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20HTML=20file=20preview=20=E2=80=94=20ren?= =?UTF-8?q?der=20.html=20as=20pages,=20not=20source=20(Phase=201.1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- routers/web/repo/view_file.go | 14 ++++++++++++++ templates/repo/view_file.tmpl | 12 +++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/routers/web/repo/view_file.go b/routers/web/repo/view_file.go index 8d7721103a..d7a0b3174c 100644 --- a/routers/web/repo/view_file.go +++ b/routers/web/repo/view_file.go @@ -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 diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 59243bf684..73f1c761e2 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -125,11 +125,13 @@ - {{else if .IsAudioFile}} - - {{else}} + {{else if .IsAudioFile}} + + {{else if .IsHTMLFile}} + + {{else}}