Skip to content

Commit

Permalink
Add logic to switch between source/rendered on Markdown (go-gitea#19356)
Browse files Browse the repository at this point in the history
Adds a button to switch between the source blob and the rendered markdown.
  • Loading branch information
Gusted authored and AbdulrhmnGhanem committed Aug 23, 2022
1 parent c9a1538 commit 24a98ec
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 24a98ec

Please sign in to comment.