diff options
Diffstat (limited to 'desk/web/components/post-text.hoon')
-rw-r--r-- | desk/web/components/post-text.hoon | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/desk/web/components/post-text.hoon b/desk/web/components/post-text.hoon new file mode 100644 index 0000000..0335e4e --- /dev/null +++ b/desk/web/components/post-text.hoon @@ -0,0 +1,182 @@ +/- b=boke, tp=trill-post +/+ sr=sortug, plib=trill-utils +/= poll-div /web/components/poll +|_ [s=state:b =bowl:gall] +++ content +|= c=content-map:tp ^- (list manx) +=/ latest (pry:corm:tp c) +?~ latest ~ +(content-list +.u.latest) +++ content-list +|= c=content-list:tp ^- (list manx) +(turn c block) +++ block +|= b=block:tp ^- manx +?+ -.b ;p; +%paragraph (pg +.b) +%blockquote (bq +.b) +%heading (heading +.b) +:: %table (table +.b) +%list (htmlist +.b) +%media (media +.b) +%codeblock (codeblock +.b) +%eval (eval +.b) +%ref (refblock +.b) +== +++ eval +|= txt=@t ^- manx +:: Ream can crash if the cord is wrong +:: soften instead +=/ uhoon (rush txt vest) +?~ uhoon ;p:"The hoon you tried to run ({(trip txt)}) is invalid." +=/ run %- mule |. +%+ slap !>(..zuse) u.uhoon +?: ?=(%.n -.run) :: if virtualization fails get a (list tank) +;p + ;span:"Evaluation of {(trip txt)} failed:" + ;br; + ;* %+ turn p.run |= t=tank ;span:"{~(ram re t)}" +== +;p:"{(text p.run)}" +++ pg +|= l=(list inline:tp) ^- manx +;p +;* %+ turn l inline +== +++ bq +|= l=(list inline:tp) ^- manx +;blockquote +;* %+ turn l inline +== +:: ++ table +:: |= rows=(list (list content-list:tp)) +:: ;table +:: ;* %+ turn rows +:: |= l=(list content-list:tp) +:: ;tr +:: ;* %+ turn l +:: |= cl=content-list:tp +:: ;td +:: ;* (turn cl block) +:: == +:: == +:: == +++ refblock +|= [app=term src=@p pat=path] + ?+ app ;span; + %polls (poll-loader pat) + == +++ poll-loader +|= scry-path=(pole knot) ^- manx +?. ?=([ship=@t id=@t ~] scry-path) ;span; +=/ usip (slaw %p ship.scry-path) +?~ usip ;span; +=/ uid (slaw %da id.scry-path) +?~ uid ;span; +=/ upoll (~(get by polls.s) [u.usip u.uid]) +?~ upoll ;span:"Poll not found" +(show:poll-div u.upoll bowl) + + +++ htmlist +|= [l=(list content-list:tp) ordered=?] +?: ordered +;ol + ;* %+ turn l li +== +;ul + ;* %+ turn l li +== +++ li +|= l=content-list:tp ^- manx +;li + ;* (turn l block) +== +++ media +|= m=media:tp ^- manx +?- -.m +%video ;video@"{(trip p.m)}"; +%audio ;audio@"{(trip p.m)}"; +%images ;div.images + ;* %+ turn p.m + |= [url=@t caption=@t] ;img@"{(trip url)}"(alt (trip caption)); + == +== +++ codeblock +|= [code=@t lang=@t] :: TODO lang suff +;pre +;code:"{(trip code)}" +== +++ heading +|= [pp=@t q=@] ^- manx +=/ p (trip pp) +?: .=(1 q) ;h1:"{p}" +?: .=(2 q) ;h2:"{p}" +?: .=(3 q) ;h3:"{p}" +?: .=(4 q) ;h4:"{p}" +?: .=(5 q) ;h5:"{p}" +?: .=(6 q) ;h6:"{p}" +;p:"" +++ inline +|= l=inline:tp ^- manx +?- -.l + %text (parse-text p.l) + %italic ;i:"{(trip p.l)}" + %bold ;strong:"{(trip p.l)}" + %strike ;del:"{(trip p.l)}" + %ship ;span.ship:"{(trip (scot %p p.l))}" + %codespan ;code:"{(trip p.l)}" + %link ?. (is-image:web:sr href.l) + ;a/"{(trip href.l)}"(target "_blank"):"{(trip show.l)}" + ;a/"{(trip href.l)}" + =target "_blank" + ;img@"{(trip href.l)}"(alt (trip show.l)); + == + %date + =/ s (time:enjs:format p.l) + ?. ?=(%n -.s) ;span; + ;span.timestamp(timestamp (trip p.s)):"" + %note ;span; + %break ;br; + %underline ;span.underline:"{(trip p.l)}" + %sup ;sup:"{(trip p.l)}" + %sub ;sub:"{(trip p.l)}" + %ruby ;ruby + "{(trip p.l)}" + ;rt:"{(trip q.l)}" + == +== +++ parse-text +|= txt=@t ^- manx +=/ tpe (trip txt) +=/ youtube (rush txt youtube:parsing:sr) +?^ youtube +:: ;a/"{tpe}" +:: ;img@"https://i.ytimg.com/vi/{u.youtube}/hqdefault.jpg"; +:: == +;iframe.youtube-frame@"https://www.youtube.com/embed/{u.youtube}"; +=/ twatter-status (rush txt twatter:parsing:sr) +?^ twatter-status +;div :: goddamn twatter embeds insert themselves as last child + ;a.parsed-twatter(status u.twatter-status):"{tpe}" +== +=/ trimmed (rush txt trim:parsing:sr) +?~ trimmed ~& parsing-error=txt ;span.parsing-error; +=/ link=(unit purl:eyre) (rust u.trimmed link:parsing:sr) +?^ link + ?^ p.q.u.link + ?: (is-img u.p.q.u.link) ;img@"{u.trimmed}"; + ;a.parsed-link/"{tpe}"(target "_blank"):"{tpe}" :: normal link + ;a.parsed-link/"{tpe}"(target "_blank"):"{tpe}" :: normal link +;span:"{tpe}" + +++ is-img +|= t=@ta +=/ img-set %- silt +:~ ~.webp + ~.png + ~.jpeg + ~.jpg +== +(~(has in img-set) t) +-- |