diff options
author | Unknown <joe2010xtmf@163.com> | 2014-04-07 00:47:19 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-04-07 00:47:19 -0400 |
commit | e2fe2209057b90e6c78a84b7c66c3395cf100e30 (patch) | |
tree | fd170266254876e80b9e4b3b10801b6712e3bc6e /modules/base/markdown.go | |
parent | e7c8a3cb8d26da68b09f799585c03970cd243be1 (diff) | |
download | gitea-e2fe2209057b90e6c78a84b7c66c3395cf100e30.tar.gz gitea-e2fe2209057b90e6c78a84b7c66c3395cf100e30.zip |
Work on comment
Diffstat (limited to 'modules/base/markdown.go')
-rw-r--r-- | modules/base/markdown.go | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/modules/base/markdown.go b/modules/base/markdown.go index 962e1ae1e9..828f87de5d 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -6,9 +6,11 @@ package base import ( "bytes" + "fmt" "net/http" "path" "path/filepath" + "regexp" "strings" "github.com/gogits/gfm" @@ -87,7 +89,28 @@ func (options *CustomRender) Link(out *bytes.Buffer, link []byte, title []byte, options.Renderer.Link(out, link, title, content) } +var ( + mentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`) + commitPattern = regexp.MustCompile(`[^>]http[s]{0,}.*commit/[0-9a-zA-Z]{1,}`) +) + +func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte { + ms := mentionPattern.FindAll(rawBytes, -1) + for _, m := range ms { + rawBytes = bytes.Replace(rawBytes, m, + []byte(fmt.Sprintf(`<a href="/user/%s">%s</a>`, m[1:], m)), -1) + } + ms = commitPattern.FindAll(rawBytes, -1) + for _, m := range ms { + rawBytes = bytes.Replace(rawBytes, m, + []byte(fmt.Sprintf(`<code><a href="%s">%s</a></code>`, m, m)), -1) + } + return rawBytes +} + func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte { + body := RenderSpecialLink(rawBytes, urlPrefix) + fmt.Println(string(body)) htmlFlags := 0 // htmlFlags |= gfm.HTML_USE_XHTML // htmlFlags |= gfm.HTML_USE_SMARTYPANTS @@ -115,7 +138,7 @@ func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte { extensions |= gfm.EXTENSION_SPACE_HEADERS extensions |= gfm.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK - body := gfm.Markdown(rawBytes, renderer, extensions) - + body = gfm.Markdown(body, renderer, extensions) + fmt.Println(string(body)) return body } |