Skip to content

Fix plain readme didn't render correctly on repo home page #2705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/view_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down