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
release/v1.2
Lunny Xiao 7 years ago committed by Bo-Yi Wu
parent fb80265b52
commit 785ba171f4

@ -93,16 +93,12 @@ func renderDirectory(ctx *context.Context, treeLink string) {
if isTextFile { if isTextFile {
d, _ := ioutil.ReadAll(dataRc) d, _ := ioutil.ReadAll(dataRc)
buf = append(buf, d...) buf = append(buf, d...)
newbuf := markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas()) ctx.Data["IsRenderedHTML"] = true
if newbuf != nil { if markup.Type(readmeFile.Name()) != "" {
ctx.Data["IsMarkdown"] = true ctx.Data["FileContent"] = string(markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas()))
} else { } else {
// FIXME This is the only way to show non-markdown files ctx.Data["FileContent"] = string(bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1))
// instead of a broken "View Raw" link
ctx.Data["IsMarkdown"] = true
newbuf = bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1)
} }
ctx.Data["FileContent"] = string(newbuf)
} }
} }
@ -188,15 +184,14 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
d, _ := ioutil.ReadAll(dataRc) d, _ := ioutil.ReadAll(dataRc)
buf = append(buf, d...) buf = append(buf, d...)
tp := markup.Type(blob.Name()) readmeExist := markup.IsReadmeFile(blob.Name())
isSupportedMarkup := tp != ""
// FIXME: currently set IsMarkdown for compatible
ctx.Data["IsMarkdown"] = isSupportedMarkup
readmeExist := isSupportedMarkup || markup.IsReadmeFile(blob.Name())
ctx.Data["ReadmeExist"] = readmeExist ctx.Data["ReadmeExist"] = readmeExist
if readmeExist && isSupportedMarkup { if markup.Type(blob.Name()) != "" {
ctx.Data["IsRenderedHTML"] = true
ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas())) ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
} else if readmeExist {
ctx.Data["IsRenderedHTML"] = true
ctx.Data["FileContent"] = string(bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1))
} else { } else {
// Building code view blocks with line number on server side. // Building code view blocks with line number on server side.
var fileContent string var fileContent string

@ -36,8 +36,8 @@
{{end}} {{end}}
</h4> </h4>
<div class="ui attached table segment"> <div class="ui attached table segment">
<div class="file-view {{if .IsMarkdown}}markdown{{else if .IsTextFile}}code-view{{end}} has-emoji"> <div class="file-view {{if .IsRenderedHTML}}markdown{{else if .IsTextFile}}code-view{{end}} has-emoji">
{{if .IsMarkdown}} {{if .IsRenderedHTML}}
{{if .FileContent}}{{.FileContent | Str2html}}{{end}} {{if .FileContent}}{{.FileContent | Str2html}}{{end}}
{{else if not .IsTextFile}} {{else if not .IsTextFile}}
<div class="view-raw ui center"> <div class="view-raw ui center">

Loading…
Cancel
Save