Skip to content

Commit ee769f7

Browse files
author
Gusted
authored
Add logic to switch between source/rendered on Markdown (#19356)
Adds a button to switch between the source blob and the rendered markdown.
1 parent 6d51b9f commit ee769f7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

routers/web/repo/view.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,17 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
489489
}
490490

491491
rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc))
492+
493+
shouldRenderSource := ctx.FormString("display") == "source"
492494
readmeExist := markup.IsReadmeFile(blob.Name())
493495
ctx.Data["ReadmeExist"] = readmeExist
494-
if markupType := markup.Type(blob.Name()); markupType != "" {
496+
497+
markupType := markup.Type(blob.Name())
498+
if markupType != "" {
499+
ctx.Data["HasSourceRenderedToggle"] = true
500+
}
501+
502+
if markupType != "" && !shouldRenderSource {
495503
ctx.Data["IsMarkup"] = true
496504
ctx.Data["MarkupType"] = markupType
497505
var result strings.Builder
@@ -507,7 +515,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
507515
return
508516
}
509517
ctx.Data["EscapeStatus"], ctx.Data["FileContent"] = charset.EscapeControlString(result.String())
510-
} else if readmeExist {
518+
} else if readmeExist && !shouldRenderSource {
511519
buf := &bytes.Buffer{}
512520
ctx.Data["IsRenderedHTML"] = true
513521

0 commit comments

Comments
 (0)