aboutsummaryrefslogtreecommitdiff
path: root/renderer
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2022-03-30 15:52:30 +0000
committerr <r@freesoftwareextremist.com>2022-03-30 15:52:30 +0000
commit2d49ff9fb4ea9b0e88df1621e954246bc1851de6 (patch)
tree9f156fa571beb14135dc5ab36030458dfc8ca4e5 /renderer
parentc390a0c32720f6afe852bc7a3a3f64c3afe9e401 (diff)
downloadbloat-2d49ff9fb4ea9b0e88df1621e954246bc1851de6.tar.gz
bloat-2d49ff9fb4ea9b0e88df1621e954246bc1851de6.zip
Switch to html/template
Diffstat (limited to 'renderer')
-rw-r--r--renderer/renderer.go13
1 files changed, 8 insertions, 5 deletions
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)(&gt;.*)(<br|$)")
-func statusContentFilter(spoiler, content string, emojis []mastodon.Emoji, mentions []mastodon.Mention) string {
- if len(spoiler) > 0 {
- content = spoiler + "<br/>" + content
- }
+func statusContentFilter(content string, emojis []mastodon.Emoji, mentions []mastodon.Mention) string {
content = quoteRE.ReplaceAllString(content, `$1<span class="quote">$2</span>$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