mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 12:15:43 +01:00
Fix #138
This commit is contained in:
parent
a913aff1d0
commit
f979d0d6b9
1 changed files with 24 additions and 5 deletions
|
@ -97,12 +97,31 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte {
|
func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte {
|
||||||
ms := MentionPattern.FindAll(rawBytes, -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 {
|
for _, m := range ms {
|
||||||
rawBytes = bytes.Replace(rawBytes, m,
|
line = bytes.Replace(line, m,
|
||||||
[]byte(fmt.Sprintf(`<a href="/user/%s">%s</a>`, m[1:], m)), -1)
|
[]byte(fmt.Sprintf(`<a href="/user/%s">%s</a>`, m[1:], m)), -1)
|
||||||
}
|
}
|
||||||
ms = commitPattern.FindAll(rawBytes, -1)
|
}
|
||||||
|
|
||||||
|
buf.Write(line)
|
||||||
|
buf.Write(lineBreak)
|
||||||
|
}
|
||||||
|
|
||||||
|
rawBytes = buf.Bytes()
|
||||||
|
ms := commitPattern.FindAll(rawBytes, -1)
|
||||||
for _, m := range ms {
|
for _, m := range ms {
|
||||||
m = bytes.TrimSpace(m)
|
m = bytes.TrimSpace(m)
|
||||||
i := strings.Index(string(m), "commit/")
|
i := strings.Index(string(m), "commit/")
|
||||||
|
|
Loading…
Reference in a new issue