diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-10-16 16:30:11 +0800 |
---|---|---|
committer | Bo-Yi Wu <appleboy.tw@gmail.com> | 2017-10-16 03:30:11 -0500 |
commit | 785ba171f4db76da17bc0ce7ceeaf2983664fc1f (patch) | |
tree | 537206be9406847ba2cbbac45c52d8ccbc791bc5 | |
parent | fb80265b52321df92f17ed398506b60e186ca300 (diff) | |
download | gitea-785ba171f4db76da17bc0ce7ceeaf2983664fc1f.tar.gz gitea-785ba171f4db76da17bc0ce7ceeaf2983664fc1f.zip |
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
-rw-r--r-- | routers/repo/view.go | 25 | ||||
-rw-r--r-- | templates/repo/view_file.tmpl | 4 |
2 files changed, 12 insertions, 17 deletions
diff --git a/routers/repo/view.go b/routers/repo/view.go index 84e5ba85ce..3d5b18948f 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -93,16 +93,12 @@ func renderDirectory(ctx *context.Context, treeLink string) { if isTextFile { d, _ := ioutil.ReadAll(dataRc) buf = append(buf, d...) - newbuf := markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas()) - if newbuf != nil { - ctx.Data["IsMarkdown"] = true + ctx.Data["IsRenderedHTML"] = true + if markup.Type(readmeFile.Name()) != "" { + ctx.Data["FileContent"] = string(markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas())) } else { - // FIXME This is the only way to show non-markdown files - // instead of a broken "View Raw" link - ctx.Data["IsMarkdown"] = true - newbuf = bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1) + ctx.Data["FileContent"] = string(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) buf = append(buf, d...) - tp := markup.Type(blob.Name()) - isSupportedMarkup := tp != "" - // FIXME: currently set IsMarkdown for compatible - ctx.Data["IsMarkdown"] = isSupportedMarkup - - readmeExist := isSupportedMarkup || markup.IsReadmeFile(blob.Name()) + readmeExist := markup.IsReadmeFile(blob.Name()) 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())) + } else if readmeExist { + ctx.Data["IsRenderedHTML"] = true + ctx.Data["FileContent"] = string(bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1)) } else { // Building code view blocks with line number on server side. var fileContent string diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 36fccb00b3..c68da4fae5 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -36,8 +36,8 @@ {{end}} </h4> <div class="ui attached table segment"> - <div class="file-view {{if .IsMarkdown}}markdown{{else if .IsTextFile}}code-view{{end}} has-emoji"> - {{if .IsMarkdown}} + <div class="file-view {{if .IsRenderedHTML}}markdown{{else if .IsTextFile}}code-view{{end}} has-emoji"> + {{if .IsRenderedHTML}} {{if .FileContent}}{{.FileContent | Str2html}}{{end}} {{else if not .IsTextFile}} <div class="view-raw ui center"> |