Now possible to @ someone
This commit is contained in:
parent
e79e1fdf45
commit
a3fdc78c5c
1 changed files with 7 additions and 0 deletions
|
|
@ -19,6 +19,7 @@ type Status struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var urlRegexp = regexp.MustCompile(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)`)
|
var urlRegexp = regexp.MustCompile(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)`)
|
||||||
|
var userRegexp = regexp.MustCompile(`@([a-z0-9-_]+)\b`)
|
||||||
|
|
||||||
func (s Status) ContentDisplay() string {
|
func (s Status) ContentDisplay() string {
|
||||||
content := html.EscapeString(s.Content)
|
content := html.EscapeString(s.Content)
|
||||||
|
|
@ -29,6 +30,12 @@ func (s Status) ContentDisplay() string {
|
||||||
content = strings.Replace(content, url, fmt.Sprintf("<a href=\"%s\" target=\"_blank\">%s</a>", url, url), 1)
|
content = strings.Replace(content, url, fmt.Sprintf("<a href=\"%s\" target=\"_blank\">%s</a>", url, url), 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if userRegexp.MatchString(s.Content) {
|
||||||
|
matches := userRegexp.FindAllStringSubmatch(s.Content, -1)
|
||||||
|
for _, m := range matches {
|
||||||
|
content = strings.Replace(content, m[0], fmt.Sprintf("<a href=\"https://status.cafe/users/%s\" target=\"_blank\">%s</a>", m[1], m[0]), 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue