on a397efd help sign in
205 lines 4.5 kB history raw
1/- *gemtext
2|%
3:: mark conversion functions
4::
5++ to-docu
6 |%
7 :: convert %gmi mark to %docu mark
8 ::
9 ++ gmi
10 |= gem=(list gmni)
11 ^- manx
12 |^
13 =/ res (reel gem process)
14 ;div
15 ;* ?~ acc.res out.res
16 [(make-list acc.res) out.res]
17 ==
18 :: Convert each gmni type to manx
19 :: and accumulate
20 ::
21 ++ process
22 |= [g=gmni acc=(list @t) out=marl]
23 ?- -.g
24 %list [[text.g acc] out]
25 ::
26 %text
27 :- ~
28 ?: =('' text.g)
29 ?~(acc out [(make-list acc) out])
30 :_ ?~(acc out [(make-list acc) out])
31 ^- manx
32 ;p: {(trip text.g)}
33 ::
34 %link
35 :- ~
36 :_ ?~(acc out [(make-list acc) out])
37 ^- manx
38 ;p
39 ;a/"{(trip link.g)}"
40 ;+ ;/ ?~ text.g
41 (trip link.g)
42 (trip u.text.g)
43 ==
44 ==
45 ::
46 %code
47 :- ~
48 :_ ?~(acc out [(make-list acc) out])
49 ^- manx
50 ?~ alt.g
51 ;pre: {(trip text.g)}
52 ;pre(class (lang u.alt.g)): {(trip text.g)}
53 ::
54 %quot
55 :- ~
56 :_ ?~(acc out [(make-list acc) out])
57 ^- manx
58 ;blockquote: {(trip text.g)}
59 ::
60 %head
61 :- ~
62 :_ ?~(acc out [(make-list acc) out])
63 ^- manx
64 ?- lvl.g
65 %1 ;h1: {(trip text.g)}
66 %2 ;h2: {(trip text.g)}
67 %3 ;h3: {(trip text.g)}
68 ==
69 ==
70 :: convert codeblock alt-text to
71 :: language class
72 ::
73 ++ lang
74 |= =@t
75 ^- tape
76 %+ scan (cass (trip t))
77 %+ funk "language-"
78 (star ;~(pose aln (cold '-' next)))
79 :: assemble individual bullet points
80 ::
81 ++ make-list
82 |= items=(list @t)
83 ^- manx
84 ;ul
85 ;* %+ turn items
86 |= =@t
87 ^- manx
88 ;li: {(trip t)}
89 ==
90 --
91 ::
92 :: convert a %txt mark to a %docu mark
93 ::
94 ++ txt
95 |= tex=wain
96 ^- manx
97 |^
98 ;div
99 ;* (turn (make-paras tex) reprocess)
100 ==
101 :: useful parsing short-hands
102 ::
103 ++ eof ;~(less next (easy ~))
104 ++ white (mask "\09 ")
105 ++ blank ;~(plug (star white) (just '\0a'))
106 ++ hard-wrap (cold ' ' ;~(plug blank (star white)))
107 ++ one-space (cold ' ' (plus white))
108 :: first pass of text file, separating and
109 :: processing paragraphs
110 ::
111 ++ make-paras
112 |= tex=wain
113 ^- (list tape)
114 %+ rash
115 (of-wain:format tex)
116 ;~ pose
117 (cold ~ (full empty))
118 ;~(pfix (star empty) (plus para))
119 ==
120 :: separate paragraph from text body,
121 :: rejoining hard-wrapped lines,
122 :: collapsing whitespace and removing
123 :: leading/trailing whitespace
124 ::
125 ++ para
126 %+ ifix
127 [(star white) empty]
128 %- plus
129 ;~ less
130 empty
131 ;~ pose
132 hard-wrap
133 one-space
134 next
135 ==
136 ==
137 :: breaks between paragraphs
138 ::
139 ++ empty
140 ;~ pose
141 ;~(plug blank (plus blank))
142 ;~(plug (star white) eof)
143 ;~(plug blank (star white) eof)
144 ==
145 :: reprocess a paragraph, distinguishing
146 :: code and plaintext
147 ::
148 ++ reprocess
149 |= =tape
150 ^- manx
151 ;p
152 ;* %+ scan tape
153 (plus ;~(pose code plain))
154 ==
155 :: inline plaintext
156 ::
157 ++ plain
158 %+ cook
159 |= =tape
160 ^- manx
161 ;/(tape)
162 %- plus
163 ;~ less
164 code
165 next
166 ==
167 :: convert atoms, arms and wings to inline code
168 ::
169 ++ code
170 %+ cook
171 |= =tape
172 ^- manx
173 ;code
174 ;+ ;/(tape)
175 ==
176 ;~ pose
177 :: ++arm +*of +$some:kind
178 ::
179 ;~ plug
180 lus ;~(pose lus buc tar)
181 low (star ;~(pose nud low hep col))
182 ==
183 :: non-constant atom
184 ::
185 %+ cook |=(=coin ~(rend co coin))
186 ;~ simu
187 ;~ pose
188 sig dot hep
189 ;~(plug (just '0') low)
190 ==
191 nuck:so
192 ==
193 :: .wing.refence
194 ::
195 %+ cook |=(=(list tape) `tape`(zing list))
196 %- plus
197 ;~(plug dot low (star ;~(pose nud low hep)))
198 :: %constant
199 ::
200 %+ cook |=(=coin "%{~(rend co coin)}")
201 ;~(pfix cen nuck:so)
202 ==
203 --
204 --
205--