all repos — honk @ 4383bba0663db4b587d2af9f4f49d1c742bf94bb

my fork of honk

allow mention by direct url
Ted Unangst tedu@tedunangst.com
Fri, 19 Apr 2019 12:35:31 -0400
commit

4383bba0663db4b587d2af9f4f49d1c742bf94bb

parent

2586b3b49e60f3f6f4305d494efde27bfbd86ac9

1 files changed, 18 insertions(+), 2 deletions(-)

jump to
M fun.gofun.go

@@ -93,16 +93,21 @@ where string

} var re_mentions = regexp.MustCompile(`@[[:alnum:]]+@[[:alnum:].]+`) +var re_urltions = regexp.MustCompile(`@https://\S+`) func grapevine(s string) []string { + var mentions []string m := re_mentions.FindAllString(s, -1) - var mentions []string for i := range m { where := gofish(m[i]) if where != "" { mentions = append(mentions, where) } } + m = re_urltions.FindAllString(s, -1) + for i := range m { + mentions = append(mentions, m[i][1:]) + } return mentions }

@@ -115,6 +120,10 @@ if where != "" {

mentions = append(mentions, Mention{who: m[i], where: where}) } } + m = re_urltions.FindAllString(s, -1) + for i := range m { + mentions = append(mentions, Mention{who: m[i][1:], where: m[i][1:]}) + } return mentions }

@@ -123,7 +132,7 @@ ID string

Name string } -var re_link = regexp.MustCompile(`https?://[^\s"]+[\w/)]`) +var re_link = regexp.MustCompile(`@?https?://[^\s"]+[\w/)]`) var re_emus = regexp.MustCompile(`:[[:alnum:]_]+:`) func herdofemus(noise string) []Emu {

@@ -143,6 +152,9 @@ s = strings.TrimSpace(s)

s = strings.Replace(s, "\r", "", -1) s = html.EscapeString(s) linkfn := func(url string) string { + if url[0] == '@' { + return url + } addparen := false adddot := false if strings.HasSuffix(url, ")") && strings.IndexByte(url, '(') == -1 {

@@ -173,6 +185,10 @@ }

who := m[0 : 1+strings.IndexByte(m[1:], '@')] return fmt.Sprintf(`<span class="h-card"><a class="u-url mention" href="%s">%s</a></span>`, html.EscapeString(where), html.EscapeString(who)) + }) + s = re_urltions.ReplaceAllStringFunc(s, func(m string) string { + return fmt.Sprintf(`<span class="h-card"><a class="u-url mention" href="%s">%s</a></span>`, + html.EscapeString(m[1:]), html.EscapeString(m)) }) return s }