summaryrefslogtreecommitdiff
path: root/desk/lib/json.hoon
blob: 37ecb03cadff18b256cfbc2e93b73be4b9f20ebf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/+  sortug
|%
++  de
=,  dejs:format
|%
++  boardpost
%-  ar  %-  ot
:~  author+so
    op+so
    thread+de-date
    date+de-date
    title+so
    content+(ar content)
    id+ni
    tid+ni
==
++  comment
%-  ar  %-  ot
:~  author+so
    date+de-date
    content+(ar content)
    pa+so
    parent+de-date
    post+de-date
    title+so
==
++  soo
|=  jon=json 
?~  jon  ''
?>(?=([%s *] jon) p.jon)
++  poast
%-  ar  
%-  ot
:~  title+so
    url+de-url
    content+(ar content)
    date+di
    tags+de-tags
    id+ni
==
++  de-tags
|=  j=json  ^-  (set @t)
?>  ?=(%s -.j)
=/  ret  (rush +.j (split:parsing:sortug hep))
%-  sy
?~  ret  ~[+.j]  %+  roll  u.ret  |=  [=tape acc=(list @t)]  ?~  tape  acc  [(crip tape) acc]
++  de-date   ::  just use di?
|=  j=json  ^-  @da
?>  ?=(%n -.j)
=/  n  (rash +.j dem)
(from-unix-ms:chrono:userlib n)
++  off
|*  wer=(pole [cord fist])
  |=  jon=json
  ?>  ?=([%o [@ *] ~ ~] jon)
  |-
  ?-    wer
      :: [[key=@t wit=*] t=*]
      [[key=@t *] t=*]
    =>  .(wer [[* wit] *]=wer)
    ?:  =(key.wer p.n.p.jon)
      [key.wer ~|(key+key.wer (wit.wer q.n.p.jon))]
    ?~  t.wer  ~|(bad-key+p.n.p.jon !!)
    ((of t.wer) jon)
  ==
++  content
%-  of
:~  paragraph+(ar inline)
    blockquote+(ar inline)
    heading+heading
    list+clists
    media+media
    codeblock+dcode
    tasklist+(ar de-task)
    eval+so
    ref+ref
    json+external
==
++  inline
|=  jon=json  %.  jon
%-  of
:~  text+so
    italic+so
    bold+so
    strike+so
    ship+(se %p)
    date+di
    note+de-note
    codespan+so
    link+link
    break+ul
    underline+so
    sup+so
    sub+so
    ruby+de-ruby
==
++  de-task
%-  ot
:~  text+(ar inline)
    done+bo
==
++  de-note
%-  ot
:~  id+so
    text+(ar inline)
==
++  de-ruby
%-  ot
:~  p+so
    q+so
==
++  dcode
%-  ot
:~  code+so
    lang+so
==
++  link
%-  ot
:~  href+so
    show+so
==
++  heading
%-  ot
:~  text+so
    :-  %num
    |=  j=json
    ?>  ?=(%n -.j)
    =/  n  (rash +.j dem)
    ?:  .=(1 n)  %h1
    ?:  .=(2 n)  %h2
    ?:  .=(3 n)  %h3
    ?:  .=(4 n)  %h4
    ?:  .=(5 n)  %h5
    ?:  .=(6 n)  %h6  %h6
==
++  clists
|=  jon=json
%.  jon
%-  ot
:~  :-  %text
    |=  j=json  =/  i  ((ar inline) j)
    ~[~[[%paragraph i]]]
    ordered+bo
==  
++  media
%-  of
:~  images+(ar de-image)
    video+so
    audio+so
==
++  de-image
%-  ot
:~  url+so
    caption+so
==
++  ref
%-  ot
:~  type+(se %tas)
    ship+(se %p)
    path+dpath
==
++  external
%-  ot
:~  origin+(se %tas)
    content+so
==
++  dpath  :: from resource
%-  su  
%+  cook
|=  l=(list @t)  `path`+.l
(more fas urs:ab)
++  de-url  :: from resource
%-  su
%+  cook
|=  l=(list @t)  `path`l
=/  f  (cook |=(a=tape (crip a)) (star ;~(less fas next)))
(more fas f)
--
--