]> source.dussan.org Git - gitea.git/commitdiff
Fix plain readme didn't render correctly on repo home page (#2705)
authorLunny Xiao <xiaolunwen@gmail.com>
Mon, 16 Oct 2017 07:04:34 +0000 (15:04 +0800)
committerKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>
Mon, 16 Oct 2017 07:04:34 +0000 (09:04 +0200)
* fix plain readme didn't render correctly on repo home page

* fix missing render

* remove unused template variables

routers/repo/view.go
templates/repo/view_file.tmpl

index fa1087fe093043c99a1ae6271e2d33890ec4c737..e8e1bacc4efadad039468b176021952b8d202a96 100644 (file)
@@ -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.
index 898b9b555763193cc113bf23211e3b2490993b5f..c68da4fae5f085dba73c510668f749d1018f05f7 100644 (file)
@@ -36,8 +36,8 @@
                {{end}}
        </h4>
        <div class="ui attached table segment">
-               <div class="file-view {{if .IsMarkup}}markdown{{else if .IsTextFile}}code-view{{end}} has-emoji">
-                       {{if .IsMarkup}}
+               <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">