This commit is contained in:
Philip C Monk 2014-12-08 19:01:42 -05:00
commit 4dacd26a4b
6 changed files with 1447 additions and 227 deletions

View File

@ -680,7 +680,7 @@
::
++ poxa :: xml parser
=< |=(a=cord (rush a apex))
|%
|_ ent=_`(map term ,@t)`[[%apos '\''] ~ ~]
++ apex
=+ spa=;~(pose comt whit)
%+ knee *manx |. ~+
@ -706,7 +706,7 @@
::
++ chrd :: character data
%+ cook |=(a=tape ^-(mars :/(a)))
(plus ;~(less soq doq ;~(pose (just `@`10) escp)))
(plus ;~(less doq ;~(pose (just `@`10) escp)))
::
++ comt :: comments
=- (ifix [(jest '<!--') (jest '-->')] (star -))
@ -716,15 +716,19 @@
;~(less (jest '-->') hep)
==
::
++ escp
++ escp ;~(pose ;~(less gal gar pam prn) enty)
++ enty :: entity
%+ ifix pam^sem
;~ pose
;~(less gal gar pam prn)
(cold '>' (jest '&gt;'))
(cold '<' (jest '&lt;'))
(cold '&' (jest '&amp;'))
(cold '"' (jest '&quot;'))
(cold '\'' (jest '&apos;'))
=+ def=`_ent`(mo [%gt '>'] [%lt '<'] [%amp '&'] [%quot '"'] ~)
%+ sear ~(get by (~(uni by def) ent))
(cook crip ;~(plug alf (stun 1^31 aln)))
%+ cook |=(a=@c ?:((gth a 0x10.ffff) '<27>' (tuft a)))
=< ;~(pfix hax ;~(pose - +))
:- (bass 10 (stun 1^8 dit))
(bass 16 ;~(pfix (mask "xX") (stun 1^8 hit)))
==
::
++ empt :: self-closing tag
%+ ifix [gal (jest '/>')]
;~(plug ;~(plug name attr) (cold ~ (star whit)))

View File

@ -6,6 +6,8 @@
::
::::
::
// /%%/parse :: inli donp parse
// /%%/rend :: sing sung sang flat into-inner
:: ~% %utyl +>+>+> ~
|_ don=down
++ grab :: convert from
@ -18,13 +20,13 @@
++ mark
~/ %dawn
|= p=@t
*down
(rash p parse)
--
++ noun down :: clam from %noun
--
::
++ grow :: convert into
=< |%
|%
++ hymn :: convert to %hymn
;html
;head:title:"Untitled"
@ -34,211 +36,7 @@
==
++ psal :: convert to %psal
;div
;* (apex don)
==
--
!: |%
::
++ into-inner
|= [a=marl b=manx]
?~ c.b b(c a)
$(b i.c.b)
::
++ flat
|= a=marl
^- tape
?~ a ~
%- weld :_ $(a t.a)
^- tape
?~ n.g.i.a
?>(?=(_:/(**) i.a) v.i.a.g.i.a)
?+ n.g.i.a $(a c.i.a)
%img
%- zing ^- wall
%+ murn a.g.i.a |= [a=mane b=tape]
^- (unit tape)
?+ a ~
%alt [~ b]
==
==
::
++ sang :: tight item children
|= a=(list elem)
^- marl
?~ a ~
%- weld :_ $(a t.a)
?. ?=(%para -.i.a)
(sing i.a ~)
(sung p.i.a)
::
++ sing :: elem to manx
=> |%
++ first-word
|= a=tape
=. a (trip (crip a)) :: XX valid tapes
^- (unit tape)
=. a q.q:(need q:((star ace) [1 1] a))
=+ vex=((plus ;~(less ace prn)) [1 1] a)
?~ q.vex ~
(some (wonk vex))
--
=+ [tig=| had=*(unit mane)]
|= lum=(list elem)
|^ ^- marl
=+ a=apex
?~ q.a
p.a
(weld p.a $(lum q.a))
::
++ apex
^- [p=marl q=_lum]
?~ lum
?~ had [~ ~]
(lose "unclosed {<u.had>}")
=> [ele=i.lum .(lum t.lum)]
?. ?=(%html -.ele)
(push (reso ele) ~)
=+ tex=(trip (role p.ele))
=^ mar tex [p q.q]:(need q:(many:poxa 1^1 tex))
?^ mar
(push mar)
=^ hed lum (chomp tex head:poxa)
?^ hed
=+ max=`marx`u.hed
(push(lum q) [max p] ~):[apex(had `n.max) .]
=^ tal lum (chomp tex tail:poxa)
?~ tal
(push ;lost:"{tex}" ~)
?: =(had tal)
[~ lum]
?^ had
=. lum [ele lum]
(lose "unclosed {<u.had>}")
(lose "close {<u.tal>}")
::
++ lose |=(a=tape [[;lost:"{a}"]~ lum])
++ chomp
|* [tap=tape fel=_rule]
^- [(unit ,_(wonk *fel)) _lum]
=+ vex=(fel 1^1 tap)
?~ q.vex [~ lum]
:- [~ (wonk vex)]
?~(q.q.u.q.vex lum [[%html (crip q.q.u.q.vex) ~] lum])
::
++ push
|= a=marl
^+ apex
?~ a apex
[[b p] q]:[b=i.a (push t.a)]
::
++ reso
|= a=elem
?^ -.a
=. tig ?.(?=(%list -.p.a) tig p.p.a)
?: &(tig ?=(%item -.p.a))
[/li (sang q.a)]
%+ into-inner ^$(lum q.a)
?- -.p.a
%bloq ;blockquote;
%item ;li;
%list ?@ q.p.a ;ul;
?: =(1 p.q.p.a) ;ol;
=+ num=(pojo (jone p.q.p.a))
;ol(start num);
==
?- -.a :: :/("unimplemented {<p.a>}")
%html !! :: handled earlier XX do type stuff
%para [/p (sung p.a)]
%head [/(add %h0 (lsh 3 1 p.a)) (sung q.a)]
%hrul ;hr;
:: %html
::=+ tex=(role (turn p.a crip))
::=+ (poxa tex)
::?^ - u.-
::=+ (rush tex (star ;~(pose gah comt:poxa)))
::?^ - :/(~)
::;lost: {<p.a>}
:: :/([(role (turn p.a crip))]~) :: XX haaaaaaack
%defn :/(~)
%code =+ lan=?~(p.a ~ (first-word r.u.p.a))
=+ tex=(trip (role q.a))
?~ lan ;pre:code:"{tex}"
;pre:code(class "language-{u.lan}"):"{tex}"
==
--
::
++ sung
|= lim=kids
=+ had=*(unit mane)
|^ ^- marl
=+ a=apex
?~ q.a
p.a
(weld p.a $(lim q.a))
::
++ apex
^- [p=marl q=_lim]
?~ lim
?~ had [~ ~]
(lose "unclosed {<u.had>}")
=> [ele=i.lim .(lim t.lim)]
?. ?=(%htmt -.ele)
(push (reso ele) ~)
=+ tex=(trip p.ele)
=^ hed lim (chomp tex head:poxa)
?^ hed
=+ max=`marx`u.hed
(push(lim q) [max p] ~):[apex(had `n.max) .]
=^ tal lim (chomp tex tail:poxa)
?~ tal
(push ;lost:"{tex}" ~)
?: =(had tal)
[~ lim]
?^ had
=. lim [ele lim]
(lose "unclosed {<u.had>}")
(lose "close {<u.tal>}")
::
++ lose |=(a=tape [[;lost:"{a}"]~ lim])
++ chomp
|* [tap=tape fel=_rule]
^- [(unit ,_(wonk *fel)) _lim]
=+ vex=(fel 1^1 tap)
?~ q.vex [~ lim]
:- [~ (wonk vex)]
?~(q.q.u.q.vex lim [[%htmt (crip q.q.u.q.vex)] lim])
::
++ push
|= a=marl
^+ apex
?~ a apex
[[b p] q]:[b=i.a (push t.a)]
::
++ reso
|= b=inline
^- manx
?@ -.b
?- -.b
%$ =.(p.b (trip (crip p.b)) :/(p.b)) :: XX valid tapes
%line ;br;
%code ;code:"{p.b}"
%htmt !! ::p.b :: handled earlier :: XX do type stuff
==
?: ?=(%blot -.p.b)
=+ res=`manx`;img(src p.p.b, alt (flat (turn q.b ..$)));
:: ;img@"{p.p.b}";
?~ q.p.b res
res(a.g (welp a.g.res title/u.q.p.b ~))
?: ?=([[%emph ?] [[%emph ?] *] ~] b)
[/strong ^$(lim q.i.q.b)]
%+ into-inner ^$(lim q.b)
?- p.b
[%emph ?] ?.(p.p.b ;em; ;strong;)
[%delt ~] ;del;
[%link ^] ?~ q.p.b ;a/"{p.p.b}";
;a/"{p.p.b}"(title u.q.p.b);
;* (sing don)
==
--
--
--

File diff suppressed because one or more lines are too long

1195
main/mar/down/parse.hoon Normal file

File diff suppressed because it is too large Load Diff

222
main/mar/down/rend.hoon Normal file
View File

@ -0,0 +1,222 @@
:: ++down rendering arms
::
::::
::
|%
++ into-inner
|= [a=marl b=manx]
?~ c.b b(c a)
$(b i.c.b)
::
++ flat
|= a=marl
^- tape
?~ a ~
%- weld :_ $(a t.a)
^- tape
?~ n.g.i.a
?>(?=(_:/(**) i.a) v.i.a.g.i.a)
?+ n.g.i.a $(a c.i.a)
%img
%- zing ^- wall
%+ murn a.g.i.a |= [a=mane b=tape]
^- (unit tape)
?+ a ~
%alt [~ b]
==
==
::
++ sang :: tight item children
|= a=(list elem)
^- marl
?~ a ~
%- weld :_ $(a t.a)
?. ?=(%para -.i.a)
(sing i.a ~)
(sung p.i.a)
::
++ sing :: elem to manx
=> |%
++ first-word
|= a=tape
=. a (trip (crip a)) :: XX valid tapes
^- (unit tape)
=. a q.q:(need q:((star ace) [1 1] a))
=+ vex=((plus ;~(less ace prn)) [1 1] a)
?~ q.vex ~
(some (wonk vex))
--
=+ [tig=| had=*(unit mane)]
|= lum=(list elem)
|^ ^- marl
=+ a=apex
?~ q.a
p.a
(weld p.a $(lum q.a))
::
++ apex
^- [p=marl q=_lum]
?~ lum
?~ had [~ ~]
(lose "unclosed {<u.had>}")
=> [ele=i.lum .(lum t.lum)]
?. ?=(%html -.ele)
(push (reso ele) ~)
=+ tex=(trip (role p.ele))
=^ mar tex [p q.q]:(need q:(many:poxa 1^1 tex))
?^ mar
(push mar)
=^ hed lum (chomp tex head:poxa)
?^ hed
=+ max=`marx`u.hed
(push(lum q) [max p] ~):[apex(had `n.max) .]
=^ tal lum (chomp tex tail:poxa)
?~ tal
(push ;lost:"{tex}" ~)
?: =(had tal)
[~ lum]
?^ had
=. lum [ele lum]
(lose "unclosed {<u.had>}")
(lose "close {<u.tal>}")
::
++ lose |=(a=tape [[;lost:"{a}"]~ lum])
++ chomp
|* [tap=tape fel=_rule]
^- [(unit ,_(wonk *fel)) _lum]
=+ vex=(fel 1^1 tap)
?~ q.vex [~ lum]
:- [~ (wonk vex)]
?~(q.q.u.q.vex lum [[%html (crip q.q.u.q.vex) ~] lum])
::
++ push
|= a=marl
^+ apex
?~ a apex
[[b p] q]:[b=i.a (push t.a)]
::
++ reso
|= a=elem
?^ -.a
=. tig ?.(?=(%list -.p.a) tig p.p.a)
?: &(tig ?=(%item -.p.a))
[/li (sang q.a)]
%+ into-inner ^$(lum q.a)
?- -.p.a
%bloq ;blockquote;
%item ;li;
%list ?@ q.p.a ;ul;
?: =(1 p.q.p.a) ;ol;
=+ num=(pojo (jone p.q.p.a))
;ol(start num);
==
?- -.a :: :/("unimplemented {<p.a>}")
%html !! :: handled earlier XX do type stuff
%para [/p (sung p.a)]
%head [/(add %h0 (lsh 3 1 p.a)) (sung q.a)]
%hrul ;hr;
:: %html
::=+ tex=(role (turn p.a crip))
::=+ (poxa tex)
::?^ - u.-
::=+ (rush tex (star ;~(pose gah comt:poxa)))
::?^ - :/(~)
::;lost: {<p.a>}
:: :/([(role (turn p.a crip))]~) :: XX haaaaaaack
%defn :/(~)
%code =+ lan=?~(p.a ~ (first-word r.u.p.a))
=+ tex=(trip (role q.a))
?~ lan ;pre:code:"{tex}"
;pre:code(class "language-{u.lan}"):"{tex}"
==
--
::
++ sung
|= lim=kids
=+ had=*(unit mane)
|^ ^- marl
=+ a=apex
?~ q.a
p.a
(weld p.a $(lim q.a))
::
++ apex
^- [p=marl q=_lim]
?~ lim
?~ had [~ ~]
(lose "unclosed {<u.had>}")
=> [ele=i.lim .(lim t.lim)]
?. ?=(%htmt -.ele)
(push (reso ele) ~)
=+ tex=(trip p.ele)
=^ emo lim (chomp tex empt:poxa)
?^ emo
=+ man=`manx`u.emo
(push man ~)
=^ hed lim (chomp tex head:poxa)
?^ hed
=+ max=`marx`u.hed
(push(lim q) [max p] ~):[apex(had `n.max) .]
=^ tal lim (chomp tex tail:poxa)
?~ tal
(push ;lost:"{tex}" ~)
?: =(had tal)
[~ lim]
?^ had
=. lim [ele lim]
(lose "unclosed {<u.had>}")
(lose "close {<u.tal>}")
::
++ lose |=(a=tape [[;lost:"{a}"]~ lim])
++ chomp
|* [tap=tape fel=_rule]
^- [(unit ,_(wonk *fel)) _lim]
=+ vex=(fel 1^1 tap)
?~ q.vex [~ lim]
:- [~ (wonk vex)]
?~(q.q.u.q.vex lim [[%htmt (crip q.q.u.q.vex)] lim])
::
++ push
|= a=marl
^+ apex
?~ a apex
[[b p] q]:[b=i.a (push t.a)]
::
++ urly
|= a=tape ^- tape
?~ a ~
:: ?: (gth i.a 0xff) "XX" :: XX
?: ?| [?=(^ q)]:(alp 1^1 a)
(~(has in (sa "!*'();:@&=+$,/?#%.~_")) i.a) :: XX reparse
==
[i.a $(a t.a)]
(weld (urle (trip i.a)) $(a t.a))
::
++ reso
|= b=inline
^- manx
?@ -.b
?- -.b
%$ =.(p.b (trip (crip p.b)) :/(p.b)) :: XX valid tapes
%line ;br;
%code ;code:"{p.b}"
%htmt !! ::p.b :: handled earlier :: XX do type stuff
==
?: ?=(%blot -.p.b)
=+ res=`manx`;img(src (urly p.p.b), alt (flat (turn q.b ..$)));
:: ;img@"{p.p.b}";
?~ q.p.b res
res(a.g (welp a.g.res title/u.q.p.b ~))
:: ?: ?=([[%emph %|] [[%emph %|] *] ~] b)
:: [/strong (sung q.i.q.b)]
%+ into-inner (sung q.b)
?- p.b
[%emph ?] ?.(p.p.b ;em; ;strong;)
[%delt ~] ;del;
[%link ^] =+ url=(urly p.p.b)
?~ q.p.b ;a/"{url}";
;a/"{url}"(title u.q.p.b);
==
--
--

View File

@ -24,7 +24,7 @@
[%list p=? q=$|(char [p=@u q=char])] :: tight, ordered?
[%item ~]
==
q=(list elem)
q=down
==
:: ++ mist |*(a=_,* ,[i=a t=$|(~ (mist a))]) :: .=(%mist +(%list))
++ node :: childless block