diff options
author | 无闻 <joe2010xtmf@163.com> | 2014-12-01 11:35:18 -0500 |
---|---|---|
committer | 无闻 <joe2010xtmf@163.com> | 2014-12-01 11:35:18 -0500 |
commit | cd627ba16e25b9844e82f3ea5f2a310834a9022a (patch) | |
tree | 2f1f78fd7e679f76a74c1b7fa38ba3d6c844d1f2 | |
parent | 955899969890b3176d4327d15fba1a4f170059d8 (diff) | |
parent | d0a80e432dc240187642162180d3aadfdc56fe15 (diff) | |
download | gitea-cd627ba16e25b9844e82f3ea5f2a310834a9022a.tar.gz gitea-cd627ba16e25b9844e82f3ea5f2a310834a9022a.zip |
Merge pull request #690 from Dennis-Smurf/feature-sha1-markdown-pattern
Addded sha1 pattern in markdown for current repository
-rw-r--r-- | modules/base/markdown.go | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/modules/base/markdown.go b/modules/base/markdown.go index 7b371dbd9c..c85bd02069 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -100,10 +100,11 @@ func (options *CustomRender) Image(out *bytes.Buffer, link []byte, title []byte, } var ( - MentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`) - commitPattern = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`) - issueFullPattern = regexp.MustCompile(`(\s|^)https?.*issues/[0-9]+(#+[0-9a-zA-Z-]*)?`) - issueIndexPattern = regexp.MustCompile(`#[0-9]+`) + MentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`) + commitPattern = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`) + issueFullPattern = regexp.MustCompile(`(\s|^)https?.*issues/[0-9]+(#+[0-9a-zA-Z-]*)?`) + issueIndexPattern = regexp.MustCompile(`#[0-9]+`) + sha1CurrentPattern = regexp.MustCompile(`\b[0-9a-f]{40}\b`) ) func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte { @@ -153,7 +154,22 @@ func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte { rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf( ` <a href="%s">#%s</a>`, m, ShortSha(string(m[i+7:j])))), -1) } - ms = issueIndexPattern.FindAll(rawBytes, -1) + rawBytes = RenderissueIndexPattern(rawBytes, urlPrefix) + rawBytes = RenderSha1CurrentPattern(rawBytes, urlPrefix) + return rawBytes +} + +func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte { + ms := sha1CurrentPattern.FindAll(rawBytes, -1) + for _, m := range ms { + rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf( + `<a href="%s/commit/%s"><code>%s</code></a>`, urlPrefix, m, ShortSha(string(m)))), -1) + } + return rawBytes +} + +func RenderissueIndexPattern(rawBytes []byte, urlPrefix string) []byte { + ms := issueIndexPattern.FindAll(rawBytes, -1) for _, m := range ms { rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf( `<a href="%s/issues/%s">%s</a>`, urlPrefix, m[1:], m)), -1) |