aboutsummaryrefslogtreecommitdiffstats
path: root/modules/base/tool.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-02-20 17:10:05 -0500
committerUnknwon <u@gogs.io>2016-02-20 17:10:05 -0500
commitd5a3021a7d86a6dbf42df97c5c25e22b0b3f9505 (patch)
tree2a2c54eb587a4875b742f932398af99d140297ea /modules/base/tool.go
parentd8a994ef243349f321568f9e36d5c3f444b99cae (diff)
downloadgitea-d5a3021a7d86a6dbf42df97c5c25e22b0b3f9505.tar.gz
gitea-d5a3021a7d86a6dbf42df97c5c25e22b0b3f9505.zip
Make markdown as an independent module
Diffstat (limited to 'modules/base/tool.go')
-rw-r--r--modules/base/tool.go40
1 files changed, 24 insertions, 16 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 811a76960c..bc6ff81a14 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -15,14 +15,14 @@ import (
"hash"
"html/template"
"math"
- "regexp"
+ "net/http"
"strings"
"time"
+ "unicode"
"unicode/utf8"
"github.com/Unknwon/com"
"github.com/Unknwon/i18n"
- "github.com/microcosm-cc/bluemonday"
"github.com/gogits/chardet"
@@ -30,20 +30,6 @@ import (
"github.com/gogits/gogs/modules/setting"
)
-var Sanitizer = bluemonday.UGCPolicy()
-
-func BuildSanitizer() {
- // Normal markdown-stuff
- Sanitizer.AllowAttrs("class").Matching(regexp.MustCompile(`[\p{L}\p{N}\s\-_',:\[\]!\./\\\(\)&]*`)).OnElements("code")
-
- // Checkboxes
- Sanitizer.AllowAttrs("type").Matching(regexp.MustCompile(`^checkbox$`)).OnElements("input")
- Sanitizer.AllowAttrs("checked", "disabled").OnElements("input")
-
- // Custom URL-Schemes
- Sanitizer.AllowURLSchemes(setting.Markdown.CustomURLSchemes...)
-}
-
// EncodeMD5 encodes string to md5 hex value.
func EncodeMD5(str string) string {
m := md5.New()
@@ -504,3 +490,25 @@ func Int64sToMap(ints []int64) map[int64]bool {
}
return m
}
+
+// IsLetter reports whether the rune is a letter (category L).
+// https://github.com/golang/go/blob/master/src/go/scanner/scanner.go#L257
+func IsLetter(ch rune) bool {
+ return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch >= 0x80 && unicode.IsLetter(ch)
+}
+
+func IsTextFile(data []byte) (string, bool) {
+ contentType := http.DetectContentType(data)
+ if strings.Index(contentType, "text/") != -1 {
+ return contentType, true
+ }
+ return contentType, false
+}
+
+func IsImageFile(data []byte) (string, bool) {
+ contentType := http.DetectContentType(data)
+ if strings.Index(contentType, "image/") != -1 {
+ return contentType, true
+ }
+ return contentType, false
+}