|
@@ -89,6 +89,9 @@ var (
|
|
|
IssueNumericPattern = regexp.MustCompile(`( |^|\()#[0-9]+\b`)
|
|
|
|
|
|
IssueAlphanumericPattern = regexp.MustCompile(`( |^|\()[A-Z]{1,10}-[1-9][0-9]*\b`)
|
|
|
+
|
|
|
+
|
|
|
+ CrossReferenceIssueNumericPattern = regexp.MustCompile(`( |^)[0-9a-zA-Z]+/[0-9a-zA-Z]+#[0-9]+\b`)
|
|
|
|
|
|
|
|
|
|
|
@@ -154,7 +157,19 @@ func (r *Renderer) AutoLink(out *bytes.Buffer, link []byte, kind int) {
|
|
|
if j == -1 {
|
|
|
j = len(m)
|
|
|
}
|
|
|
- out.WriteString(fmt.Sprintf(`<a href="%s">#%s</a>`, m, base.ShortSha(string(m[i+7:j]))))
|
|
|
+
|
|
|
+ issue := string(m[i+7 : j])
|
|
|
+ fullRepoUrl := setting.AppUrl + strings.TrimPrefix(r.urlPrefix, "/")
|
|
|
+ var link string
|
|
|
+ if strings.HasPrefix(string(m), fullRepoUrl) {
|
|
|
+
|
|
|
+ link = fmt.Sprintf(`<a href="%s">#%s</a>`, m, issue)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ repo := string(m[len(setting.AppUrl) : i-1])
|
|
|
+ link = fmt.Sprintf(`<a href="%s">%s#%s</a>`, m, repo, issue)
|
|
|
+ }
|
|
|
+ out.WriteString(link)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
@@ -261,6 +276,23 @@ func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string
|
|
|
return rawBytes
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+func RenderCrossReferenceIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string]string) []byte {
|
|
|
+ ms := CrossReferenceIssueNumericPattern.FindAll(rawBytes, -1)
|
|
|
+ for _, m := range ms {
|
|
|
+ if m[0] == ' ' || m[0] == '(' {
|
|
|
+ m = m[1:]
|
|
|
+ }
|
|
|
+
|
|
|
+ repo := string(bytes.Split(m, []byte("#"))[0])
|
|
|
+ issue := string(bytes.Split(m, []byte("#"))[1])
|
|
|
+
|
|
|
+ link := fmt.Sprintf(`<a href="%s%s/issues/%s">%s</a>`, setting.AppUrl, repo, issue, m)
|
|
|
+ rawBytes = bytes.Replace(rawBytes, m, []byte(link), 1)
|
|
|
+ }
|
|
|
+ return rawBytes
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte {
|
|
|
return []byte(Sha1CurrentPattern.ReplaceAllStringFunc(string(rawBytes[:]), func(m string) string {
|
|
@@ -281,6 +313,7 @@ func RenderSpecialLink(rawBytes []byte, urlPrefix string, metas map[string]strin
|
|
|
}
|
|
|
|
|
|
rawBytes = RenderIssueIndexPattern(rawBytes, urlPrefix, metas)
|
|
|
+ rawBytes = RenderCrossReferenceIssueIndexPattern(rawBytes, urlPrefix, metas)
|
|
|
rawBytes = RenderSha1CurrentPattern(rawBytes, urlPrefix)
|
|
|
return rawBytes
|
|
|
}
|