From d21f39d0e5fd9c4ba983a91770778c9330c68a48 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Thu, 19 Sep 2019 00:50:26 -0400 Subject: [PATCH] slightly better inline img replacement --- fun.go | 15 ++++++++++++++- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/fun.go b/fun.go index 474cc01..5956fe4 100644 --- a/fun.go +++ b/fun.go @@ -19,7 +19,6 @@ import ( "crypto/rand" "crypto/rsa" "fmt" - "html" "html/template" "log" "net/http" @@ -28,12 +27,14 @@ import ( "strings" "sync" + "golang.org/x/net/html" "humungus.tedunangst.com/r/webs/htfilter" "humungus.tedunangst.com/r/webs/httpsig" ) func reverbolate(userid int64, honks []*Honk) { filt := htfilter.New() + filt.Imager = replaceimg zilences := getzilences(userid) for _, h := range honks { h.What += "ed" @@ -104,6 +105,18 @@ func reverbolate(userid int64, honks []*Honk) { } } +func replaceimg(node *html.Node) string { + src := htfilter.GetAttr(node, "src") + alt := htfilter.GetAttr(node, "alt") + //title := GetAttr(node, "title") + if htfilter.HasClass(node, "Emoji") && alt != "" { + return alt + } + alt = html.EscapeString(alt) + src = html.EscapeString(src) + return fmt.Sprintf(`<img alt="%s" src="%s">`, alt, src, src) +} + func translate(honk *Honk) { if honk.Format == "html" { return diff --git a/go.mod b/go.mod index cfb4047..6ebc431 100644 --- a/go.mod +++ b/go.mod @@ -7,5 +7,5 @@ require ( golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 golang.org/x/net v0.0.0-20190620200207-3b0461eec859 humungus.tedunangst.com/r/go-sqlite3 v1.1.3 - humungus.tedunangst.com/r/webs v0.6.5 + humungus.tedunangst.com/r/webs v0.6.6 ) diff --git a/go.sum b/go.sum index ff23af5..6d8b6ad 100644 --- a/go.sum +++ b/go.sum @@ -21,5 +21,5 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9ga8k38geUI= humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M= -humungus.tedunangst.com/r/webs v0.6.5 h1:5XOwH9sPeIEVn5t3a2Pvs1/2Ywt3xtjG1G3+6OEXkDY= -humungus.tedunangst.com/r/webs v0.6.5/go.mod h1:Ho+nmafD/aUWF7LnH+Yl2/b0ob7f2pCkXm4onteWvLE= +humungus.tedunangst.com/r/webs v0.6.6 h1:qepe+N9waCqLzOwhSws5pxpwSxNxdYRktJB1gY8Q3NQ= +humungus.tedunangst.com/r/webs v0.6.6/go.mod h1:Ho+nmafD/aUWF7LnH+Yl2/b0ob7f2pCkXm4onteWvLE=