slightly better inline img replacement
This commit is contained in:
parent
3b4f0d3bb0
commit
d21f39d0e5
15
fun.go
15
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="<a href="%s">%s<a>">`, alt, src, src)
|
||||
}
|
||||
|
||||
func translate(honk *Honk) {
|
||||
if honk.Format == "html" {
|
||||
return
|
||||
|
|
2
go.mod
2
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
|
||||
)
|
||||
|
|
4
go.sum
4
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=
|
||||
|
|
Loading…
Reference in New Issue