slightly better inline img replacement
Ted Unangst tedu@tedunangst.com
Thu, 19 Sep 2019 00:50:26 -0400
M
fun.go
→
fun.go
@@ -19,7 +19,6 @@ import (
"crypto/rand" "crypto/rsa" "fmt" - "html" "html/template" "log" "net/http"@@ -28,12 +27,14 @@ "regexp"
"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"@@ -102,6 +103,18 @@ }
} h.Donks = h.Donks[:j] } +} + +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="<a href="%s">%s<a>">`, alt, src, src) } func translate(honk *Honk) {
M
go.mod
→
go.mod
@@ -7,5 +7,5 @@ github.com/mattn/go-runewidth v0.0.4
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 )
M
go.sum
→
go.sum
@@ -21,5 +21,5 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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=