Skip to content

Commit 481c66a

Browse files
HarvsGzeripath
authored andcommitted
Allows external rendering of other filetypes 2 (#8300)
* allow external rendering of other filetypes fixes #4996 and #7614 allows rendering of non-tex files, or otherwise accounted for filetypes * Moves flie-size check before read() And performs gofmt -s * Only reads if markType is detected
1 parent 28f60bb commit 481c66a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

routers/repo/view.go

+14
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,20 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
346346
ctx.Data["IsAudioFile"] = true
347347
case base.IsImageFile(buf):
348348
ctx.Data["IsImageFile"] = true
349+
default:
350+
if fileSize >= setting.UI.MaxDisplayFileSize {
351+
ctx.Data["IsFileTooLarge"] = true
352+
break
353+
}
354+
355+
if markupType := markup.Type(blob.Name()); markupType != "" {
356+
d, _ := ioutil.ReadAll(dataRc)
357+
buf = append(buf, d...)
358+
ctx.Data["IsMarkup"] = true
359+
ctx.Data["MarkupType"] = markupType
360+
ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
361+
}
362+
349363
}
350364

351365
if ctx.Repo.CanEnableEditor() {

0 commit comments

Comments
 (0)