mirror of https://github.com/gogs/gogs.git
Fix unexpected rendering of README when it is not in Markdown
This patch also handles case when a file name looks like README but is not a text file (e.g. image, PDF).pull/4060/head
parent
d1c327d508
commit
8cb903fbbb
|
@ -3,7 +3,7 @@ Gogs - Go Git Service [
|

|
||||||
|
|
||||||
##### Current tip version: 0.9.116 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions ~~or submit a task on [alpha stage automated binary building system](https://build.gogs.io/)~~)
|
##### Current tip version: 0.9.117 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions ~~or submit a task on [alpha stage automated binary building system](https://build.gogs.io/)~~)
|
||||||
|
|
||||||
| Web | UI | Preview |
|
| Web | UI | Preview |
|
||||||
|:-------------:|:-------:|:-------:|
|
|:-------------:|:-------:|:-------:|
|
||||||
|
|
2
gogs.go
2
gogs.go
|
@ -16,7 +16,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.9.116.0124"
|
const APP_VER = "0.9.117.0125"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setting.AppVer = APP_VER
|
setting.AppVer = APP_VER
|
||||||
|
|
|
@ -61,7 +61,9 @@ var (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extensions that are not same as highlight classes.
|
// Extensions that are not same as highlight classes.
|
||||||
highlightMapping = map[string]string{}
|
highlightMapping = map[string]string{
|
||||||
|
".txt": "nohighlight",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewContext() {
|
func NewContext() {
|
||||||
|
|
|
@ -20,11 +20,11 @@
|
||||||
"outputPathIsOutsideProject": 0,
|
"outputPathIsOutsideProject": 0,
|
||||||
"outputPathIsSetByUser": 0
|
"outputPathIsSetByUser": 0
|
||||||
},
|
},
|
||||||
"\/css\/semantic-2.2.1.min.css": {
|
"\/css\/semantic-2.2.7.min.css": {
|
||||||
"fileType": 16,
|
"fileType": 16,
|
||||||
"ignore": 0,
|
"ignore": 1,
|
||||||
"ignoreWasSetByUser": 0,
|
"ignoreWasSetByUser": 1,
|
||||||
"inputAbbreviatedPath": "\/css\/semantic-2.2.1.min.css",
|
"inputAbbreviatedPath": "\/css\/semantic-2.2.7.min.css",
|
||||||
"outputAbbreviatedPath": "No Output Path",
|
"outputAbbreviatedPath": "No Output Path",
|
||||||
"outputPathIsOutsideProject": 0,
|
"outputPathIsOutsideProject": 0,
|
||||||
"outputPathIsSetByUser": 0
|
"outputPathIsSetByUser": 0
|
||||||
|
@ -150,12 +150,12 @@
|
||||||
"outputStyle": 1,
|
"outputStyle": 1,
|
||||||
"syntaxCheckerStyle": 1
|
"syntaxCheckerStyle": 1
|
||||||
},
|
},
|
||||||
"\/js\/semantic-2.2.1.min.js": {
|
"\/js\/semantic-2.2.7.min.js": {
|
||||||
"fileType": 64,
|
"fileType": 64,
|
||||||
"ignore": 1,
|
"ignore": 1,
|
||||||
"ignoreWasSetByUser": 1,
|
"ignoreWasSetByUser": 1,
|
||||||
"inputAbbreviatedPath": "\/js\/semantic-2.2.1.min.js",
|
"inputAbbreviatedPath": "\/js\/semantic-2.2.7.min.js",
|
||||||
"outputAbbreviatedPath": "\/js\/min\/semantic-2.2.1.min-min.js",
|
"outputAbbreviatedPath": "\/js\/min\/semantic-2.2.7.min-min.js",
|
||||||
"outputPathIsOutsideProject": 0,
|
"outputPathIsOutsideProject": 0,
|
||||||
"outputPathIsSetByUser": 0,
|
"outputPathIsSetByUser": 0,
|
||||||
"outputStyle": 1,
|
"outputStyle": 1,
|
||||||
|
|
|
@ -1303,7 +1303,11 @@ footer .ui.language .menu {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
.repository.file.list #file-content .view-raw img {
|
.repository.file.list #file-content .view-raw img {
|
||||||
padding: 5px 5px 0 5px;
|
margin-bottom: -5px;
|
||||||
|
}
|
||||||
|
.repository.file.list #file-content .plain-text {
|
||||||
|
font-size: 14px;
|
||||||
|
padding: 10px 15px;
|
||||||
}
|
}
|
||||||
.repository.file.list #file-content .code-view * {
|
.repository.file.list #file-content .code-view * {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
|
|
@ -247,10 +247,14 @@
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
img {
|
img {
|
||||||
padding: 5px 5px 0 5px;
|
margin-bottom: -5px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.plain-text {
|
||||||
|
font-size: 14px;
|
||||||
|
padding: 10px 15px;
|
||||||
|
}
|
||||||
.code-view {
|
.code-view {
|
||||||
* {
|
* {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
|
|
@ -79,9 +79,8 @@ func renderDirectory(ctx *context.Context, treeLink string) {
|
||||||
buf = buf[:n]
|
buf = buf[:n]
|
||||||
|
|
||||||
isTextFile := base.IsTextFile(buf)
|
isTextFile := base.IsTextFile(buf)
|
||||||
ctx.Data["FileIsText"] = isTextFile
|
ctx.Data["IsTextFile"] = isTextFile
|
||||||
ctx.Data["FileName"] = readmeFile.Name()
|
ctx.Data["FileName"] = readmeFile.Name()
|
||||||
// FIXME: what happens when README file is an image?
|
|
||||||
if isTextFile {
|
if isTextFile {
|
||||||
d, _ := ioutil.ReadAll(dataRc)
|
d, _ := ioutil.ReadAll(dataRc)
|
||||||
buf = append(buf, d...)
|
buf = append(buf, d...)
|
||||||
|
@ -156,10 +155,9 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
|
||||||
isMarkdown := markdown.IsMarkdownFile(blob.Name())
|
isMarkdown := markdown.IsMarkdownFile(blob.Name())
|
||||||
ctx.Data["IsMarkdown"] = isMarkdown
|
ctx.Data["IsMarkdown"] = isMarkdown
|
||||||
|
|
||||||
readmeExist := isMarkdown || markdown.IsReadmeFile(blob.Name())
|
readmeExist := isMarkdown && markdown.IsReadmeFile(blob.Name())
|
||||||
ctx.Data["ReadmeExist"] = readmeExist
|
ctx.Data["ReadmeExist"] = readmeExist
|
||||||
if readmeExist {
|
if readmeExist {
|
||||||
// TODO: don't need to render if it's a README but not Markdown file.
|
|
||||||
ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
|
ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
|
||||||
} else {
|
} else {
|
||||||
// Building code view blocks with line number on server side.
|
// Building code view blocks with line number on server side.
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.9.116.0124
|
0.9.117.0125
|
|
@ -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 .IsMarkdown}}markdown{{else if .ReadmeInList}}plain-text{{else if .IsTextFile}}code-view{{end}} has-emoji">
|
||||||
{{if .IsMarkdown}}
|
{{if or .IsMarkdown .ReadmeInList}}
|
||||||
{{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">
|
||||||
|
|
|
@ -52,6 +52,6 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{{if .ReadmeExist}}
|
{{if and .ReadmeExist .IsTextFile}}
|
||||||
{{template "repo/view_file" .}}
|
{{template "repo/view_file" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Loading…
Reference in New Issue