mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 09:09:02 +00:00
Add logic to switch between source/rendered on Markdown (#19356)
Adds a button to switch between the source blob and the rendered markdown.
This commit is contained in:
parent
6d51b9f615
commit
ee769f7459
|
@ -489,9 +489,17 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
|
||||||
}
|
}
|
||||||
|
|
||||||
rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc))
|
rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc))
|
||||||
|
|
||||||
|
shouldRenderSource := ctx.FormString("display") == "source"
|
||||||
readmeExist := markup.IsReadmeFile(blob.Name())
|
readmeExist := markup.IsReadmeFile(blob.Name())
|
||||||
ctx.Data["ReadmeExist"] = readmeExist
|
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["IsMarkup"] = true
|
||||||
ctx.Data["MarkupType"] = markupType
|
ctx.Data["MarkupType"] = markupType
|
||||||
var result strings.Builder
|
var result strings.Builder
|
||||||
|
@ -507,7 +515,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["EscapeStatus"], ctx.Data["FileContent"] = charset.EscapeControlString(result.String())
|
ctx.Data["EscapeStatus"], ctx.Data["FileContent"] = charset.EscapeControlString(result.String())
|
||||||
} else if readmeExist {
|
} else if readmeExist && !shouldRenderSource {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
ctx.Data["IsRenderedHTML"] = true
|
ctx.Data["IsRenderedHTML"] = true
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue