summaryrefslogtreecommitdiffstats
path: root/modules/base/markdown.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-12 19:32:35 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-12 19:32:35 -0400
commitf979d0d6b9ae2c4b5c553df13dfe49b81d8396c1 (patch)
treea8768f3d61ea3c32d9bf6a6cb825592e34cf9ca5 /modules/base/markdown.go
parenta913aff1d06d638ed2b54d2beaba00e88056e25f (diff)
downloadgitea-f979d0d6b9ae2c4b5c553df13dfe49b81d8396c1.tar.gz
gitea-f979d0d6b9ae2c4b5c553df13dfe49b81d8396c1.zip
Fix #138
Diffstat (limited to 'modules/base/markdown.go')
-rw-r--r--modules/base/markdown.go29
1 files changed, 24 insertions, 5 deletions
diff --git a/modules/base/markdown.go b/modules/base/markdown.go
index 057e1b0477..0825decb44 100644
--- a/modules/base/markdown.go
+++ b/modules/base/markdown.go
@@ -97,12 +97,31 @@ var (
)
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)
+ buf := bytes.NewBufferString("")
+ inCodeBlock := false
+ codeBlockPrefix := []byte("```")
+ lineBreak := []byte("\n")
+ tab := []byte("\t")
+ lines := bytes.Split(rawBytes, lineBreak)
+ for _, line := range lines {
+ if bytes.HasPrefix(line, codeBlockPrefix) {
+ inCodeBlock = !inCodeBlock
+ }
+
+ if !inCodeBlock && !bytes.HasPrefix(line, tab) {
+ ms := MentionPattern.FindAll(line, -1)
+ for _, m := range ms {
+ line = bytes.Replace(line, m,
+ []byte(fmt.Sprintf(`<a href="/user/%s">%s</a>`, m[1:], m)), -1)
+ }
+ }
+
+ buf.Write(line)
+ buf.Write(lineBreak)
}
- ms = commitPattern.FindAll(rawBytes, -1)
+
+ rawBytes = buf.Bytes()
+ ms := commitPattern.FindAll(rawBytes, -1)
for _, m := range ms {
m = bytes.TrimSpace(m)
i := strings.Index(string(m), "commit/")