aboutsummaryrefslogtreecommitdiff
path: root/modules/base/markdown.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/base/markdown.go')
-rw-r--r--modules/base/markdown.go15
1 files changed, 6 insertions, 9 deletions
diff --git a/modules/base/markdown.go b/modules/base/markdown.go
index 265deffa..dac51ebc 100644
--- a/modules/base/markdown.go
+++ b/modules/base/markdown.go
@@ -31,16 +31,10 @@ func isalnum(c byte) bool {
return (c >= '0' && c <= '9') || isletter(c)
}
-var validLinks = [][]byte{[]byte("http://"), []byte("https://"), []byte("ftp://"), []byte("mailto://")}
+var validLinksPattern = regexp.MustCompile(`^[a-z][\w-]+://`)
func isLink(link []byte) bool {
- for _, prefix := range validLinks {
- if len(link) > len(prefix) && bytes.Equal(bytes.ToLower(link[:len(prefix)]), prefix) && isalnum(link[len(prefix)]) {
- return true
- }
- }
-
- return false
+ return validLinksPattern.Match(link)
}
func IsMarkdownFile(name string) bool {
@@ -157,6 +151,8 @@ func (options *CustomRender) ListItem(out *bytes.Buffer, text []byte, flags int)
var (
svgSuffix = []byte(".svg")
svgSuffixWithMark = []byte(".svg?")
+ spaceBytes = []byte(" ")
+ spaceEncodedBytes = []byte("%20")
)
func (r *CustomRender) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) {
@@ -172,7 +168,8 @@ func (r *CustomRender) Image(out *bytes.Buffer, link []byte, title []byte, alt [
if link[0] != '/' {
prefix += "/"
}
- link = []byte(prefix + string(link))
+ link = bytes.Replace([]byte((prefix + string(link))), spaceBytes, spaceEncodedBytes, -1)
+ fmt.Println(333, string(link))
}
}