Link hashtag bug (#121)

* link + hashtag bug

* remove printlns

* tidy up some duplicated code
This commit is contained in:
Tobi Smethurst
2021-07-29 13:18:22 +02:00
committed by GitHub
parent ea8ad8b346
commit a940a520d3
15 changed files with 349 additions and 97 deletions

View File

@@ -19,9 +19,6 @@
package text
import (
"fmt"
"strings"
"github.com/russross/blackfriday/v2"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
@@ -39,20 +36,11 @@ func (f *formatter) FromMarkdown(md string, mentions []*gtsmodel.Mention, tags [
// do the markdown parsing *first*
content = string(blackfriday.Run([]byte(content), blackfriday.WithExtensions(bfExtensions)))
// format mentions nicely
for _, menchie := range mentions {
targetAccount := &gtsmodel.Account{}
if err := f.db.GetByID(menchie.TargetAccountID, targetAccount); err == nil {
mentionContent := fmt.Sprintf(`<span class="h-card"><a href="%s" class="u-url mention">@<span>%s</span></a></span>`, targetAccount.URL, targetAccount.Username)
content = strings.ReplaceAll(content, menchie.NameString, mentionContent)
}
}
// format tags nicely
for _, tag := range tags {
tagContent := fmt.Sprintf(`<a href="%s" class="mention hashtag" rel="tag">#<span>%s</span></a>`, tag.URL, tag.Name)
content = strings.ReplaceAll(content, fmt.Sprintf("#%s", tag.Name), tagContent)
}
content = f.ReplaceTags(content, tags)
// format mentions nicely
content = f.ReplaceMentions(content, mentions)
return postformat(content)
}