Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic to switch between source/rendered on Markdown #19356

Merged
merged 6 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,8 @@ file_view_source = View Source
file_view_rendered = View Rendered
file_view_raw = View Raw
file_permalink = Permalink
file_view_source_blob = View Source Blob
file_view_rendered_blob = View Rendered Blob
Gusted marked this conversation as resolved.
Show resolved Hide resolved
file_too_large = The file is too large to be shown.
bidi_bad_header = `This file contains unexpected Bidirectional Unicode characters!`
bidi_bad_description = `This file contains unexpected Bidirectional Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.`
Expand Down
9 changes: 7 additions & 2 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,14 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
}

rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc))
readmeExist := markup.IsReadmeFile(blob.Name())
shouldRenderMarkdown := !ctx.FormBool("plain")
readmeExist := markup.IsReadmeFile(blob.Name()) && shouldRenderMarkdown
Gusted marked this conversation as resolved.
Show resolved Hide resolved
ctx.Data["ReadmeExist"] = readmeExist
if markupType := markup.Type(blob.Name()); markupType != "" {

markupType := markup.Type(blob.Name())
ctx.Data["IsMarkdownBlob"] = markupType != ""

if markupType != "" && shouldRenderMarkdown {
Gusted marked this conversation as resolved.
Show resolved Hide resolved
ctx.Data["IsMarkup"] = true
ctx.Data["MarkupType"] = markupType
var result strings.Builder
Expand Down
6 changes: 6 additions & 0 deletions templates/repo/view_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
{{end}}
{{if not .ReadmeInList}}
<div class="ui buttons mr-2">
{{if and .IsMarkdownBlob .IsMarkup}}
<a class="ui mini basic button" href="{{.RepoLink}}/src/{{.BranchNameSubURL}}/{{PathEscapeSegments .TreePath}}?plain=1">{{.i18n.Tr "repo.file_view_source_blob"}}</a>
{{end}}
{{if and .IsMarkdownBlob (not .IsMarkup)}}
<a class="ui mini basic button" href="{{.RepoLink}}/src/{{.BranchNameSubURL}}/{{PathEscapeSegments .TreePath}}">{{.i18n.Tr "repo.file_view_rendered_blob"}}</a>
{{end}}
Gusted marked this conversation as resolved.
Show resolved Hide resolved
<a class="ui mini basic button" href="{{$.RawFileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
{{if not .IsViewCommit}}
<a class="ui mini basic button" href="{{.RepoLink}}/src/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}">{{.i18n.Tr "repo.file_permalink"}}</a>
Expand Down