Skip to content

Commit 785ba17

Browse files
lunnyappleboy
authored andcommitted
Fix plain readme didn't render correctly on repo home page (#2705) (#2712)
* fix plain readme didn't render correctly on repo home page * fix missing render * remove unused template variables
1 parent fb80265 commit 785ba17

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

routers/repo/view.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,12 @@ func renderDirectory(ctx *context.Context, treeLink string) {
9393
if isTextFile {
9494
d, _ := ioutil.ReadAll(dataRc)
9595
buf = append(buf, d...)
96-
newbuf := markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas())
97-
if newbuf != nil {
98-
ctx.Data["IsMarkdown"] = true
96+
ctx.Data["IsRenderedHTML"] = true
97+
if markup.Type(readmeFile.Name()) != "" {
98+
ctx.Data["FileContent"] = string(markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas()))
9999
} else {
100-
// FIXME This is the only way to show non-markdown files
101-
// instead of a broken "View Raw" link
102-
ctx.Data["IsMarkdown"] = true
103-
newbuf = bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1)
100+
ctx.Data["FileContent"] = string(bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1))
104101
}
105-
ctx.Data["FileContent"] = string(newbuf)
106102
}
107103
}
108104

@@ -188,15 +184,14 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
188184
d, _ := ioutil.ReadAll(dataRc)
189185
buf = append(buf, d...)
190186

191-
tp := markup.Type(blob.Name())
192-
isSupportedMarkup := tp != ""
193-
// FIXME: currently set IsMarkdown for compatible
194-
ctx.Data["IsMarkdown"] = isSupportedMarkup
195-
196-
readmeExist := isSupportedMarkup || markup.IsReadmeFile(blob.Name())
187+
readmeExist := markup.IsReadmeFile(blob.Name())
197188
ctx.Data["ReadmeExist"] = readmeExist
198-
if readmeExist && isSupportedMarkup {
189+
if markup.Type(blob.Name()) != "" {
190+
ctx.Data["IsRenderedHTML"] = true
199191
ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
192+
} else if readmeExist {
193+
ctx.Data["IsRenderedHTML"] = true
194+
ctx.Data["FileContent"] = string(bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1))
200195
} else {
201196
// Building code view blocks with line number on server side.
202197
var fileContent string

templates/repo/view_file.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
{{end}}
3737
</h4>
3838
<div class="ui attached table segment">
39-
<div class="file-view {{if .IsMarkdown}}markdown{{else if .IsTextFile}}code-view{{end}} has-emoji">
40-
{{if .IsMarkdown}}
39+
<div class="file-view {{if .IsRenderedHTML}}markdown{{else if .IsTextFile}}code-view{{end}} has-emoji">
40+
{{if .IsRenderedHTML}}
4141
{{if .FileContent}}{{.FileContent | Str2html}}{{end}}
4242
{{else if not .IsTextFile}}
4343
<div class="view-raw ui center">

0 commit comments

Comments
 (0)