aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo/view.go
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2022-04-10 17:01:35 +0200
committerGitHub <noreply@github.com>2022-04-10 23:01:35 +0800
commitee769f7459ffba310563cd735f503d3d7576da60 (patch)
tree40822bd3f37dedf0c7cc3d8705495b968d355e28 /routers/web/repo/view.go
parent6d51b9f615973da9542d7fe841134acee64b6cdf (diff)
downloadgitea-ee769f7459ffba310563cd735f503d3d7576da60.tar.gz
gitea-ee769f7459ffba310563cd735f503d3d7576da60.zip
Add logic to switch between source/rendered on Markdown (#19356)
Adds a button to switch between the source blob and the rendered markdown.
Diffstat (limited to 'routers/web/repo/view.go')
-rw-r--r--routers/web/repo/view.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index 7fc178cf31..0faa01d573 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -489,9 +489,17 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
}
rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc))
+
+ shouldRenderSource := ctx.FormString("display") == "source"
readmeExist := markup.IsReadmeFile(blob.Name())
ctx.Data["ReadmeExist"] = readmeExist
- if markupType := markup.Type(blob.Name()); markupType != "" {
+
+ markupType := markup.Type(blob.Name())
+ if markupType != "" {
+ ctx.Data["HasSourceRenderedToggle"] = true
+ }
+
+ if markupType != "" && !shouldRenderSource {
ctx.Data["IsMarkup"] = true
ctx.Data["MarkupType"] = markupType
var result strings.Builder
@@ -507,7 +515,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
return
}
ctx.Data["EscapeStatus"], ctx.Data["FileContent"] = charset.EscapeControlString(result.String())
- } else if readmeExist {
+ } else if readmeExist && !shouldRenderSource {
buf := &bytes.Buffer{}
ctx.Data["IsRenderedHTML"] = true