diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-10-16 15:04:34 +0800 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-10-16 09:04:34 +0200 |
commit | a75d5c72bb9d85b2344ee98b4425290423b6e6b2 (patch) | |
tree | c731ee2429a332d796756d19efa5569fa881c3a2 /routers/repo/view.go | |
parent | c7f4f07765a96ac4b66f40167ed4207aa4e34dad (diff) | |
download | gitea-a75d5c72bb9d85b2344ee98b4425290423b6e6b2.tar.gz gitea-a75d5c72bb9d85b2344ee98b4425290423b6e6b2.zip |
Fix plain readme didn't render correctly on repo home page (#2705)
* fix plain readme didn't render correctly on repo home page
* fix missing render
* remove unused template variables
Diffstat (limited to 'routers/repo/view.go')
-rw-r--r-- | routers/repo/view.go | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/routers/repo/view.go b/routers/repo/view.go index fa1087fe09..e8e1bacc4e 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["IsMarkup"] = 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["IsMarkup"] = false - 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) } } @@ -195,14 +191,13 @@ 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 != "" - ctx.Data["IsMarkup"] = isSupportedMarkup readmeExist := markup.IsReadmeFile(blob.Name()) ctx.Data["ReadmeExist"] = readmeExist - if 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. |