composition support for inline images
Ted Unangst tedu@tedunangst.com
Tue, 22 Oct 2019 00:19:31 -0400
5 files changed,
47 insertions(+),
16 deletions(-)
M
activity.go
→
activity.go
@@ -33,7 +33,6 @@ "sync"
"time" "humungus.tedunangst.com/r/webs/cache" - "humungus.tedunangst.com/r/webs/htfilter" "humungus.tedunangst.com/r/webs/httpsig" "humungus.tedunangst.com/r/webs/image" "humungus.tedunangst.com/r/webs/junk"@@ -824,11 +823,6 @@ log.Printf("content too long. truncating")
content = content[:90001] } - // grab any inline imgs - imgfilt := htfilter.New() - imgfilt.Imager = inlineimgsfor(&xonk) - imgfilt.String(content) - // init xonk xonk.What = what xonk.XID = xid@@ -844,6 +838,7 @@ if m == user.URL {
xonk.Whofore = 1 } } + imaginate(&xonk) if isUpdate { log.Printf("something has changed! %s", xonk.XID)@@ -1023,7 +1018,7 @@ }
if !h.Public { jo["directMessage"] = true } - translate(h) + translate(h, true) h.Noise = re_memes.ReplaceAllString(h.Noise, "") jo["summary"] = html.EscapeString(h.Precis) jo["content"] = ontologize(mentionize(h.Noise))
M
docs/changelog.txt
→
docs/changelog.txt
@@ -2,6 +2,8 @@ changelog
-- next ++ Inline images in posts. Send and receive. + + Somewhat functional admin console (TTY). + More JS free fallbacks for some basic functions.@@ -13,8 +15,6 @@
+ Better markdown output. +++ Add Honk Filtering and Censorship System (HFCS). - -+ Inline images in received posts. + Times for events.
M
docs/honk.5
→
docs/honk.5
@@ -44,6 +44,11 @@ /* triple tick code blocks support syntax highlighting */
int main() { return 0; } ``` .Ed +.It images +Inline images with img tags. +.Bd -literal +<img alt="Lifecycle of a honk" src="https://example.com/diagram.png"> +.Ed .It links URLs beginning with .Dq http
M
fun.go
→
fun.go
@@ -58,7 +58,7 @@ }
if !h.Public { h.Style += " limited" } - translate(h) + translate(h, false) if h.Whofore == 2 || h.Whofore == 3 { h.URL = h.XID if h.What != "bonked" {@@ -92,7 +92,7 @@
zap := make(map[string]bool) { filt := htfilter.New() - filt.Imager = replaceimgsand(zap) + filt.Imager = replaceimgsand(zap, false) filt.SpanClasses = allowedclasses p, _ := filt.String(h.Precis) n, _ := filt.String(h.Noise)@@ -145,7 +145,7 @@ h.HTML = template.HTML(h.Noise)
} } -func replaceimgsand(zap map[string]bool) func(node *html.Node) string { +func replaceimgsand(zap map[string]bool, absolute bool) func(node *html.Node) string { return func(node *html.Node) string { src := htfilter.GetAttr(node, "src") alt := htfilter.GetAttr(node, "alt")@@ -156,7 +156,11 @@ }
d := finddonk(src) if d != nil { zap[d.XID] = true - return string(templates.Sprintf(`<img alt="%s" title="%s" src="/d/%s">`, alt, alt, d.XID)) + base := "" + if absolute { + base = "https://" + serverName + } + return string(templates.Sprintf(`<img alt="%s" title="%s" src="%s/d/%s">`, alt, alt, base, d.XID)) } return string(templates.Sprintf(`<img alt="%s" src="<a href="%s">%s<a>">`, alt, src, src)) }@@ -177,7 +181,13 @@ return ""
} } -func translate(honk *Honk) { +func imaginate(honk *Honk) { + imgfilt := htfilter.New() + imgfilt.Imager = inlineimgsfor(honk) + imgfilt.String(honk.Noise) +} + +func translate(honk *Honk, redoimages bool) { if honk.Format == "html" { return }@@ -197,9 +207,29 @@
noise = strings.TrimSpace(noise) noise = quickrename(noise, honk.UserID) noise = markitzero(noise) - honk.Noise = noise honk.Onts = oneofakind(ontologies(honk.Noise)) + + if redoimages { + zap := make(map[string]bool) + { + filt := htfilter.New() + filt.Imager = replaceimgsand(zap, true) + filt.SpanClasses = allowedclasses + p, _ := filt.String(honk.Precis) + n, _ := filt.String(honk.Noise) + honk.Precis = string(p) + honk.Noise = string(n) + } + j := 0 + for i := 0; i < len(honk.Donks); i++ { + if !zap[honk.Donks[i].XID] { + honk.Donks[j] = honk.Donks[i] + j++ + } + } + honk.Donks = honk.Donks[:j] + } } func shortxid(xid string) string {
M
web.go
→
web.go
@@ -1065,7 +1065,7 @@ }
noise = hooterize(noise) honk.Noise = noise - translate(honk) + translate(honk, false) var convoy string if rid != "" {@@ -1189,6 +1189,7 @@ honk.Donks = append(honk.Donks, donk)
} } memetize(honk) + imaginate(honk) placename := strings.TrimSpace(r.FormValue("placename")) placelat := strings.TrimSpace(r.FormValue("placelat"))