summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorlunnyxiao <xiaolunwen@gmail.com>2014-09-17 12:03:03 +0800
committerlunnyxiao <xiaolunwen@gmail.com>2014-09-17 12:03:03 +0800
commited84adb679f3de70b2bffaead20a87711c38ee3a (patch)
treeff303000a735b237c8f45bbcc8018da185beb114 /modules
parentefb68a0a96574a334a3ec791c0a7f2bc6b96d006 (diff)
downloadgitea-ed84adb679f3de70b2bffaead20a87711c38ee3a.tar.gz
gitea-ed84adb679f3de70b2bffaead20a87711c38ee3a.zip
toutf8 improved & add max git diff lines
Diffstat (limited to 'modules')
-rw-r--r--modules/base/template.go27
-rw-r--r--modules/setting/setting.go3
2 files changed, 30 insertions, 0 deletions
diff --git a/modules/base/template.go b/modules/base/template.go
index f2ae00b915..6419572912 100644
--- a/modules/base/template.go
+++ b/modules/base/template.go
@@ -8,13 +8,16 @@ import (
"bytes"
"container/list"
"encoding/json"
+ "errors"
"fmt"
"html/template"
"runtime"
"strings"
"time"
+ "code.google.com/p/mahonia"
"github.com/gogits/gogs/modules/setting"
+ "github.com/saintfish/chardet"
)
func Str2html(raw string) template.HTML {
@@ -45,6 +48,29 @@ func ShortSha(sha1 string) string {
return sha1
}
+func ToUtf8WithErr(content []byte) (error, string) {
+ detector := chardet.NewTextDetector()
+ result, err := detector.DetectBest(content)
+ if err != nil {
+ return err, ""
+ }
+
+ if result.Charset == "utf8" {
+ return nil, string(content)
+ }
+
+ decoder := mahonia.NewDecoder(result.Charset)
+ if decoder != nil {
+ return nil, decoder.ConvertString(string(content))
+ }
+ return errors.New("unknow char decoder"), string(content)
+}
+
+func ToUtf8(content string) string {
+ _, res := ToUtf8WithErr([]byte(content))
+ return res
+}
+
var mailDomains = map[string]string{
"gmail.com": "gmail.com",
}
@@ -103,6 +129,7 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
"ActionContent2Commits": ActionContent2Commits,
"Oauth2Icon": Oauth2Icon,
"Oauth2Name": Oauth2Name,
+ "ToUtf8": ToUtf8,
}
type Actioner interface {
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 199b4f2c27..011c00c08c 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -64,6 +64,7 @@ var (
// Picture settings.
PictureService string
DisableGravatar bool
+ MaxGitDiffLines int
// Log settings.
LogRootPath string
@@ -241,6 +242,8 @@ func NewConfigContext() {
[]string{"server"})
DisableGravatar = Cfg.MustBool("picture", "DISABLE_GRAVATAR")
+ MaxGitDiffLines = Cfg.MustInt("git", "MAX_GITDIFF_LINES", 5000)
+
Langs = Cfg.MustValueArray("i18n", "LANGS", ",")
Names = Cfg.MustValueArray("i18n", "NAMES", ",")
}