summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-12-25 05:45:07 -0500
committerUnknwon <u@gogs.io>2015-12-25 05:45:07 -0500
commit93f03707a789a4d538c945c9838fa4ec4d3ef15c (patch)
treecdffa6724be6466da634e69abc03ab105e6f7ae1
parent85af36332b89a42152c7e2b76af5e2aeb048103a (diff)
downloadgitea-93f03707a789a4d538c945c9838fa4ec4d3ef15c.tar.gz
gitea-93f03707a789a4d538c945c9838fa4ec4d3ef15c.zip
#2283 set text/plain for non-binary files in raw mode
-rw-r--r--modules/base/tool.go6
-rwxr-xr-xpublic/css/gogs.css2
-rw-r--r--public/less/_repository.less2
-rw-r--r--routers/repo/download.go2
-rw-r--r--templates/repo/view_file.tmpl2
5 files changed, 10 insertions, 4 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 9dcbb881d5..75f475fa4f 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -53,7 +53,11 @@ func ShortSha(sha1 string) string {
}
func DetectEncoding(content []byte) string {
- _, name, certain := charset.DetermineEncoding(content, setting.Repository.AnsiCharset)
+ _, name, certain := charset.DetermineEncoding(content, "")
+ if name != "utf-8" && len(setting.Repository.AnsiCharset) > 0 {
+ log.Debug("Using default AnsiCharset: %s", setting.Repository.AnsiCharset)
+ return setting.Repository.AnsiCharset
+ }
log.Debug("Detected encoding: %s (%v)", name, certain)
return name
}
diff --git a/public/css/gogs.css b/public/css/gogs.css
index 7bd1d2254d..1ed66997d2 100755
--- a/public/css/gogs.css
+++ b/public/css/gogs.css
@@ -1902,7 +1902,7 @@ footer .container .links > *:first-child {
margin-top: -2px;
}
.repository.file.list #file-content .view-raw * {
- width: 100%;
+ max-width: 100%;
}
.repository.file.list #file-content .view-raw img {
padding: 5px 5px 0 5px;
diff --git a/public/less/_repository.less b/public/less/_repository.less
index 14306ee8dd..9891886e88 100644
--- a/public/less/_repository.less
+++ b/public/less/_repository.less
@@ -181,7 +181,7 @@
}
.view-raw {
* {
- width: 100%;
+ max-width: 100%;
}
img {
padding: 5px 5px 0 5px;
diff --git a/routers/repo/download.go b/routers/repo/download.go
index cb863c6133..a10792b87f 100644
--- a/routers/repo/download.go
+++ b/routers/repo/download.go
@@ -28,6 +28,8 @@ func ServeData(ctx *middleware.Context, name string, reader io.Reader) error {
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+path.Base(ctx.Repo.TreeName))
ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary")
}
+ } else {
+ ctx.Resp.Header().Set("Content-Type", "text/plain")
}
ctx.Resp.Write(buf)
_, err := io.Copy(ctx.Resp, reader)
diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl
index 44d74f9c9b..44fc44913e 100644
--- a/templates/repo/view_file.tmpl
+++ b/templates/repo/view_file.tmpl
@@ -28,7 +28,7 @@
{{if .ReadmeExist}}
{{if .FileContent}}{{.FileContent | Str2html}}{{end}}
{{else if not .IsFileText}}
- <div class="view-raw">
+ <div class="view-raw ui center">
{{if .IsImageFile}}
<img src="{{EscapePound .FileLink}}">
{{else}}