diff --git a/renderer/renderer.go b/renderer/renderer.go index 20a3c05..6e50270 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -1,11 +1,11 @@ package renderer import ( + "html/template" "io" "regexp" "strconv" "strings" - "text/template" "time" "bloat/mastodon" @@ -54,10 +54,7 @@ func emojiFilter(content string, emojis []mastodon.Emoji) string { var quoteRE = regexp.MustCompile("(?mU)(^|> *|\n)(>.*)( 0 { - content = spoiler + "
" + content - } +func statusContentFilter(content string, emojis []mastodon.Emoji, mentions []mastodon.Mention) string { content = quoteRE.ReplaceAllString(content, `$1$2$3`) var replacements []string for _, e := range emojis { @@ -129,6 +126,10 @@ func withContext(data interface{}, ctx *Context) TemplateData { return TemplateData{data, ctx} } +func raw(s string) template.HTML { + return template.HTML(s) +} + type Renderer interface { Render(ctx *Context, writer io.Writer, page string, data interface{}) (err error) } @@ -148,6 +149,8 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) { "FormatTimeRFC3339": formatTimeRFC3339, "FormatTimeRFC822": formatTimeRFC822, "WithContext": withContext, + "HTML": template.HTMLEscapeString, + "Raw": raw, }).ParseGlob(templateGlobPattern) if err != nil { return diff --git a/service/service.go b/service/service.go index 64c7bf0..cda42f8 100644 --- a/service/service.go +++ b/service/service.go @@ -711,7 +711,7 @@ func (s *service) UserSearchPage(c *client, if len(results.Statuses) == 20 { offset += 20 nextLink = fmt.Sprintf("/usersearch/%s?q=%s&offset=%d", id, - url.QueryEscape(q), offset) + q, offset) } if len(q) > 0 { @@ -770,7 +770,7 @@ func (s *service) SearchPage(c *client, (qType == "statuses" && len(results.Statuses) == 20) { offset += 20 nextLink = fmt.Sprintf("/search?q=%s&type=%s&offset=%d", - url.QueryEscape(q), qType, offset) + q, qType, offset) } if len(q) > 0 { diff --git a/templates/header.tmpl b/templates/header.tmpl index 8eb53f6..1abb6dd 100644 --- a/templates/header.tmpl +++ b/templates/header.tmpl @@ -17,7 +17,7 @@ {{if .RefreshInterval}} {{end}} - {{if gt .Count 0}}({{.Count}}){{end}} {{.Title | html}} + {{if gt .Count 0}}({{.Count}}){{end}} {{.Title}} {{if .CustomCSS}} diff --git a/templates/list.tmpl b/templates/list.tmpl index 1b15278..dcc6ee8 100644 --- a/templates/list.tmpl +++ b/templates/list.tmpl @@ -33,7 +33,7 @@
- +
diff --git a/templates/nav.tmpl b/templates/nav.tmpl index e7a7981..db88aa0 100644 --- a/templates/nav.tmpl +++ b/templates/nav.tmpl @@ -8,7 +8,7 @@
- {{EmojiFilter (html .Account.DisplayName) .Account.Emojis}} + {{EmojiFilter (HTML .Account.DisplayName) .Account.Emojis | Raw}} followed you - @@ -48,7 +48,7 @@
- {{EmojiFilter (html .Account.DisplayName) .Account.Emojis}} + {{EmojiFilter (HTML .Account.DisplayName) .Account.Emojis | Raw}} wants to follow you - diff --git a/templates/requestlist.tmpl b/templates/requestlist.tmpl index d9b2b0a..1a51e31 100644 --- a/templates/requestlist.tmpl +++ b/templates/requestlist.tmpl @@ -9,7 +9,7 @@
-
{{EmojiFilter (html .DisplayName) .Emojis}}
+
{{EmojiFilter (HTML .DisplayName) .Emojis | Raw}}
@{{.Acct}}
diff --git a/templates/search.tmpl b/templates/search.tmpl index 7338cad..0473d4a 100644 --- a/templates/search.tmpl +++ b/templates/search.tmpl @@ -5,7 +5,7 @@
- + diff --git a/templates/status.tmpl b/templates/status.tmpl index dda1d79..fd0940f 100644 --- a/templates/status.tmpl +++ b/templates/status.tmpl @@ -5,7 +5,7 @@ avatar - {{EmojiFilter (html .Account.DisplayName) .Account.Emojis}} + {{EmojiFilter (HTML .Account.DisplayName) .Account.Emojis | Raw}} @{{.Account.Acct}} @@ -23,7 +23,7 @@
- {{EmojiFilter (html .Account.DisplayName) .Account.Emojis}} + {{EmojiFilter (HTML .Account.DisplayName) .Account.Emojis | Raw}} @{{.Account.Acct}} @@ -91,7 +91,10 @@ {{end}}
{{if (or .Content .SpoilerText)}} -
{{StatusContentFilter (html .SpoilerText) .Content .Emojis .Mentions}}
+
+ {{if .SpoilerText}}{{EmojiFilter (HTML .SpoilerText) .Emojis | Raw}}
{{end}} + {{StatusContentFilter .Content .Emojis .Mentions | Raw}} +
{{end}} {{if .MediaAttachments}}
@@ -156,12 +159,12 @@ {{range $i, $o := .Poll.Options}}
{{if (or $s.Poll.Expired $s.Poll.Voted)}} -
{{EmojiFilter (html $o.Title) $s.Emojis}} - {{$o.VotesCount}} votes
+
{{EmojiFilter (HTML $o.Title) $s.Emojis | Raw}} - {{$o.VotesCount}} votes
{{else}} {{end}}
diff --git a/templates/user.tmpl b/templates/user.tmpl index 2532a91..fd838b9 100644 --- a/templates/user.tmpl +++ b/templates/user.tmpl @@ -11,7 +11,7 @@
{{if .User.Fields}}{{range .User.Fields}} -
{{.Name}} - {{.Value}}
+
{{.Name}} - {{.Value | Raw}}
{{end}}{{end}}
diff --git a/templates/userlistitem.tmpl b/templates/userlistitem.tmpl index 51261c8..50b9d0c 100644 --- a/templates/userlistitem.tmpl +++ b/templates/userlistitem.tmpl @@ -6,7 +6,7 @@
-
{{EmojiFilter (html .DisplayName) .Emojis}}
+
{{EmojiFilter (HTML .DisplayName) .Emojis | Raw}}
@{{.Acct}}
diff --git a/templates/usersearch.tmpl b/templates/usersearch.tmpl index e95129c..52001c9 100644 --- a/templates/usersearch.tmpl +++ b/templates/usersearch.tmpl @@ -1,11 +1,11 @@ {{with .Data}} {{template "header.tmpl" (WithContext .CommonData $.Ctx)}} -
Search {{EmojiFilter (html .User.DisplayName) .User.Emojis}}'s statuses
+
Search {{EmojiFilter (HTML .User.DisplayName) .User.Emojis | Raw}}'s statuses
Query - +