aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2022-01-27 11:41:31 +0000
committerr <r@freesoftwareextremist.com>2022-01-27 11:41:31 +0000
commit03a1cd819a7eb5bc0207f750aafe8b239f310af3 (patch)
tree95aba9cdf208ace79d4459d9acf0d46ce9b369a6
parentb8bab6fcf337e6c48437d45cf192e085e19cdf49 (diff)
downloadbloat-03a1cd819a7eb5bc0207f750aafe8b239f310af3.tar.gz
bloat-03a1cd819a7eb5bc0207f750aafe8b239f310af3.zip
Refactor status filter
-rw-r--r--renderer/renderer.go25
1 files changed, 10 insertions, 15 deletions
diff --git a/renderer/renderer.go b/renderer/renderer.go
index 4911db9..0d6776c 100644
--- a/renderer/renderer.go
+++ b/renderer/renderer.go
@@ -1,7 +1,6 @@
package renderer
import (
- "fmt"
"io"
"regexp"
"strconv"
@@ -39,32 +38,28 @@ type TemplateData struct {
Ctx *Context
}
+func emojiHTML(e mastodon.Emoji, height string) string {
+ return `<img class="emoji" src="` + e.URL + `" alt=":` + e.ShortCode + `:" title=":` + e.ShortCode + `:" height="` + height + `"/>`
+}
+
func emojiFilter(content string, emojis []mastodon.Emoji) string {
var replacements []string
- var r string
for _, e := range emojis {
- r = fmt.Sprintf("<img class=\"emoji\" src=\"%s\" alt=\":%s:\" title=\":%s:\" height=\"24\" />",
- e.URL, e.ShortCode, e.ShortCode)
- replacements = append(replacements, ":"+e.ShortCode+":", r)
+ replacements = append(replacements, ":"+e.ShortCode+":", emojiHTML(e, "24"))
}
return strings.NewReplacer(replacements...).Replace(content)
}
var quoteRE = regexp.MustCompile("(?mU)(^|> *|\n)(&gt;.*)(<br|$)")
-func statusContentFilter(spoiler string, content string,
- emojis []mastodon.Emoji, mentions []mastodon.Mention) string {
-
- var replacements []string
- var r string
+func statusContentFilter(spoiler, content string, emojis []mastodon.Emoji, mentions []mastodon.Mention) string {
if len(spoiler) > 0 {
- content = spoiler + "<br />" + content
+ content = spoiler + "<br/>" + content
}
- content = quoteRE.ReplaceAllString(content, "$1<span class=\"quote\">$2</span>$3")
+ content = quoteRE.ReplaceAllString(content, `$1<span class="quote">$2</span>$3`)
+ var replacements []string
for _, e := range emojis {
- r = fmt.Sprintf("<img class=\"emoji\" src=\"%s\" alt=\":%s:\" title=\":%s:\" height=\"32\" />",
- e.URL, e.ShortCode, e.ShortCode)
- replacements = append(replacements, ":"+e.ShortCode+":", r)
+ replacements = append(replacements, ":"+e.ShortCode+":", emojiHTML(e, "32"))
}
for _, m := range mentions {
replacements = append(replacements, `"`+m.URL+`"`, `"/user/`+m.ID+`" title="@`+m.Acct+`"`)