-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhtml.html
974 lines (967 loc) · 37.3 KB
/
html.html
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
<html dir="ltr">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<title>Arc: HTML operations</title>
<link rel="shortcut icon" href="/assets/favicon.png">
<link rel="stylesheet" type="text/css" href="code.css">
<link href="/assets/bootstrap.css" rel="stylesheet">
</head>
<body style='margin:12px 50px 0'>
<div class="navbar navbar-inverse">
<div class="navbar-inner">
<ul class="nav navbar-nav">
<li><a href="/ref/">Arc 3.1</a>
<li><a href="http://tryarc.org">Try it</a></li>
<li><a href="http://github.com/arclanguage/anarki">Get it</a></li>
<li><a href="http://ycombinator.com/arc/tut.txt">Tutorial</a></li>
<li><a href="http://arclanguage.org/forum">Forum</a></li>
</ul>
</div>
</div> <!-- end of navbar -->
<div class="links">Previous: <a href="anaphoric.html">Anaphoric operations</a>
Up: <a href="index.html">Contents</a>
Next: <a href="srv.html">The Arc web server</a>
</div>
<h1 class="links">HTML operations</h1>
Arc provides a large number of operations for generating HTML. The basic operations are <code>gentag</code> to generate a standalone tag such as <code><img></code>, and <code>tag</code> to generate an open/close tag pair surrounding something. In addition, Arc provides special-purpose functions for common HTML operations.
Arc has many operations to support forms, as well as many table operations, as tables are its primary layout technique.
<p>
For example, the following code generates a simple page with text, formatting, and a link.
<pre class="repl">
(whitepage (prn "Hello world!") (para) (link "Click here") (prn "for") (prbold "more stuff"))
</pre>
<p>
The basic model is <code>gentag</code> generates a stand-alone tag, <code>tag</code> generates a begin/end tag pair surrounding something, and a variety of operations can be used for many tags.
<p>
A tag in Arc can be defined with a tag spec, which is a tag followed by attributes and values. The syntax is slightly different for <code>gentag</code> and <code>tag</code>. <code>gentag</code> takes the tag, attributes and values as arguments, while <code>tag</code> takes the tag spec as a single argument followed by body code that outputs the tag content to stdout. For example:
<pre class="repl">
arc> (tostring (gentag p style "mystyle"))
"<p style=\"mystyle\">"
arc> (tostring (tag (p style "mystyle") (pr "Content.") (pr "More content")))
"<p style=\"mystyle\">Content.More content</p>"
</pre>
<p>
Most of the HTML generation in Arc is stdout-based, rather than
return-value-based. A typical HTML operation in Arc outputs a tag
to stdout and executes body code which outputs the tag contents to
stdout. The return value is generally not useful.
This programming model fits well with Arc's web server, which expects content to be written to stdout in many cases.
Note that this
programming model is different from the standard functional programming
model, but it has the advantage that the outputs from multiple functions
can be collected and concatenated. For example,
<pre class="repl">
arc> (tostring (underline (prn "hello") (prn "world")))
"<u>hello\nworld\n</u>"
</pre>
(In the examples, the code is wrapped in <code>tostring</code> to explicitly capture stdout for clarity, but <code>tostring</code> normally wouldn't be used when implementing web pages.)
<p>
However, some HTML operations don't collect output from the body code, but use explicit arguments. For example,
<pre class="repl">
arc> (tostring (row 1 2))
"<tr><td>1</td><td>2</td></tr>"
</pre>
Other HTML operations accept either a list of atom arguments, or body code that outputs to stdout, but not a mixture. For example,
<pre class="repl">
arc> (tostring (td (pr "hi")))
"<td>hi</td>"
arc> (tostring (td "hi"))
"<td>hi</td>"
</pre>
Arc's HTML generation is relatively inflexible. Tags can only use attributes that are explicitly registered in the attributes table. The only exception is the <code>style</code> attribute; all tags support that attribute. Other attributes are ignored with a comment in the created HTML code. The following table shows the attributes supported by Arc:
<pre>
<a class=<i>string</i> href=<i>string</i> id=<i>sym</i> onclick=<i>string</i> rel=<i>string</i>>
<body alink=<i>color</i> bgcolor=<i>color</i> leftmargin=<i>number</i> link=<i>color</i> marginheight=<i>number</i> marginwidth=<i>number</i> topmargin=<i>number</i> vlink=<i>color</i>>
<font color=<i>color</i> face=<i>string</i> size=<i>number</i>>
<form action=<i>string</i> method=<i>sym</i>>
<hr color=<i>color</i>>
<img align=<i>sym</i> border=<i>number</i> height=<i>number</i> hspace=<i>number</i> src=<i>string</i> vspace=<i>number</i> width=<i>number</i>>
<input name=<i>string</i> size=<i>number</i> type=<i>sym</i> value=<i>escaped</i>>
<option selected=<i>selected</i>>
<rss version=<i>string</i>>
<select name=<i>string</i>>
<span align=<i>string</i> class=<i>string</i> id=<i>sym</i>>
<table bgcolor=<i>color</i> border=<i>number</i> cellpadding=<i>number</i> cellspacing=<i>number</i> width=<i>string</i>>
<td align=<i>sym</i> bgcolor=<i>color</i> class=<i>string</i> colspan=<i>number</i> valign=<i>sym</i> width=<i>number</i>>
<textarea cols=<i>number</i> name=<i>string</i> rows=<i>number</i> wrap=<i>sym</i>>
<tr bgcolor=<i>color</i>>
</pre>
New tags do not need to be explicitly defined, but any desired attributes that are not listed above need to be defined using <code>attribute</code>. For instance to support the "class" attribute for <code>img</code>:
<pre class="repl">
arc> (attribute img class opstring)
arc> (tostring (gentag img class "foo"))
"<img class=\"foo\">"
</pre>
<h2>Generating HTML</h2>
<p><table class='arc'>
<tr>
<td class='arc'><a name='br'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>br</span> <span class='args'>[n]</span>
<div class='desc'>Prints <code>n</code> break tags.</div>
</td>
<td class='arc'><pre>
>(br)
<span class="stdout"><br>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='br2'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>br2</span> <span class='args'></span>
<div class='desc'>Prints two break tags.</div>
</td>
<td class='arc'><pre>
>(br2)
<span class="stdout"><br><br>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='center'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>center</span> <span class='args'>[body ...]</span>
<div class='desc'>Prints <code>body</code> in a <code>center</code> tag.</div>
</td>
<td class='arc'><pre>
>(center (pr "hello"))
<span class="stdout"><center>hello</center>
</span></pre>
<hr/>
<center>hello</center>
</td></tr>
<tr>
<td class='arc'><a name='underline'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>underline</span> <span class='args'>[body ...]</span>
<div class='desc'>Prints <code>body</code> in an underline tag.</div>
</td>
<td class='arc'><pre>
>(underline (pr "hello ") (pr "world"))
<span class="stdout"><u>hello world</u>
</span></pre>
<hr/>
<u>hello world</u>
</td></tr>
<tr>
<td class='arc'><a name='prbold'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>prbold</span> <span class='args'>[arg ...]</span>
<div class='desc'>Prints a bold (<code>b</code>) tag around <code>arg</code>.</div>
</td>
<td class='arc'><pre>
>(prbold "hello")
<span class="stdout"><b>hello</b>
</span></pre>
<hr/>
<b>hello</b>
</td></tr>
<tr>
<td class='arc'><a name='para'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>para</span> <span class='args'>[arg ...]</span>
<div class='desc'>Prints a paragraph (<code>p</code>) tag followed by the args.</div>
</td>
<td class='arc'><pre>
>(para "hello " "world")
<span class="stdout"><p>hello world
</span></pre>
<hr/>
<p>hello world
</td></tr>
<tr>
<td class='arc'><a name='whitepage'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>whitepage</span> <span class='args'>[body ...]</span>
<div class='desc'>Creates a white page containing the body.</div>
</td>
<td class='arc'><pre>
>(whitepage (prn "hello"))
<span class="stdout"><html><body bgcolor=#ffffff alink=#0000be>hello
</body>
</html>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='errpage'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>errpage</span> <span class='args'>[arg ...]</span>
<div class='desc'>Prints a white page containing the args.</div>
</td>
<td class='arc'><pre>
>(errpage "hello " "world")
<span class="stdout"><html><body bgcolor=#ffffff alink=#0000be>hello world
</body></html>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='new-hspace'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>new-hspace</span> <span class='args'>n</span>
<div class='desc'>Prints a horizonal spacer using <code>span</code>.</div>
</td>
<td class='arc'><pre>
>(new-hspace 3)
<span class="stdout"><span style="padding-left:3px" />
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='blank-url'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>blank-url</span> <span class='args'></span>
<div class='desc'>Returns path to a blank spacer GIF (<code>s.gif</code>).</div>
</td>
<td class='arc'><pre>
>(blank-url)
<span class="return">"s.gif"
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='hspace'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>hspace</span> <span class='args'>w</span>
<div class='desc'>Prints a horizontal spacer image of width <code>w</code>.</div>
</td>
<td class='arc'><pre>
>(hspace 3)
<span class="stdout"><img src="s.gif" height=1 width=3>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='vspace'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>vspace</span> <span class='args'>h</span>
<div class='desc'>Prints a vertical spacer image of height <code>h</code>.</div>
</td>
<td class='arc'><pre>
>(vspace 3)
<span class="stdout"><img src="s.gif" height=3 width=0>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='vhspace'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>vhspace</span> <span class='args'>h w</span>
<div class='desc'>Prints a spacer image of height <code>h</code> and width <code>w</code>.</div>
</td>
<td class='arc'><pre>
>(vhspace 3 5)
<span class="stdout"><img src="s.gif" height=3 width=5>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='nbsp'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>nbsp</span> <span class='args'></span>
<div class='desc'>Prints a non-breaking space.</div>
</td>
<td class='arc'><pre>
>(nbsp)
<span class="stdout">&nbsp;
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='link'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>link</span> <span class='args'>text [href [color]]</span>
<div class='desc'>Prints an HTML link.</div>
</td>
<td class='arc'><pre>
>(link "click here" "http://arcfn.com" orange)
<span class="stdout"><a href="http://arcfn.com"><font color=#ff6600>click here
</font></a>
</span></pre>
<hr/>
<a href="http://arcfn.com"><font color=#ff6600>click here</font></a>
</td></tr>
<tr>
<td class='arc'><a name='underlink'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>underlink</span> <span class='args'>text [dest]</span>
<div class='desc'>Prints an HTML link with explicitly underlined text.</div>
</td>
<td class='arc'><pre>
>(underlink "click here" "http://arcfn.com")
<span class="stdout"><a href="http://arcfn.com"><u>click here</u></a>
</span></pre>
<hr/>
<a href="http://arcfn.com"><u>click here</u></a>
</td></tr>
<tr>
<td class='arc'><a name='shortlink'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>shortlink</span> <span class='args'>url</span>
<div class='desc'>Prints a link to <code>url</code> with <code>http://</code> removed from the text.</div>
</td>
<td class='arc'><pre>
>(shortlink "http://arcfn.com")
<span class="stdout"><a href="http://arcfn.com">arcfn.com</a>
</span></pre>
<hr/>
<a href="http://arcfn.com">arcfn.com</a>
</td></tr>
<tr>
<td class='arc'><a name='parafy'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>parafy</span> <span class='args'>str</span>
<div class='desc'>Returns <code>str</code> with paragraph tags. A <code>p</code> tag is inserted after each blank line.</div>
</td>
<td class='arc'><pre>
>(parafy "hello\n\nworld\npeople")
<span class="return">"hello\n\n<p>world\npeople"
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='spanclass'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>spanclass</span> <span class='args'>classname [body ...]</span>
<div class='desc'>Prints <code>body</code> in a <code>span</code> tag.</div>
</td>
<td class='arc'><pre>
>(spanclass myclass (pr "hello ") (pr "world"))
<span class="stdout"><span class="myclass">hello world</span>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='pagemessage'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>pagemessage</span> <span class='args'>text</span>
<div class='desc'>Prints <code>text</code> followed by two breaks, if it is not <code>nil</code>.</div>
</td>
<td class='arc'><pre>
>(pagemessage "hello")
<span class="stdout">hello
<br><br>
</span></pre>
<pre>
>(pagemessage nil)
</pre>
</td></tr>
</table>
<h2>Table operations</h2>
<p><table class='arc'>
<tr>
<td class='arc'><a name='tab'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>tab</span> <span class='args'>[body ...]</span>
<div class='desc'>Prints <code>body</code> in a <code>table</code> tag.</div>
</td>
<td class='arc'><pre>
>(tab (pr "hello"))
<span class="stdout"><table border=0>hello</table>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='sptab'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>sptab</span> <span class='args'>[body ...]</span>
<div class='desc'>Prints <code>body</code> in a table tag with 0 border, 0 cellpadding, and 7 cellspacing.</div>
</td>
<td class='arc'><pre>
>(sptab (prrow "foo" 1))
<span class="stdout"><table style="border-spacing: 7px 0px;"><tr><td>foo</td>
<td align=right>1</td></tr></table>
</span></pre>
<hr/>
<table style="border-spacing: 7px 0px;"><tr><td>foo</td><td align=right>1</td></tr></table>
</td></tr>
<tr>
<td class='arc'><a name='widtable'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>widtable</span> <span class='args'>w [body ...]</span>
<div class='desc'>Prints a single-cell table containing <code>body</code>. The table has width <code>w</code>.</div>
</td>
<td class='arc'><pre>
>(widtable "30%" (pr "hello"))
<span class="stdout"><table width="30%"><tr><td>hello</td></tr></table>
</span></pre>
<hr/>
<table width="30%"><tr><td>hello</td></tr></table>
</td></tr>
<tr>
<td class='arc'><a name='zerotable'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>zerotable</span> <span class='args'>[body ...]</span>
<div class='desc'>Prints <code>body</code> in a table tag with 0 border, cellpadding, and cellspacing.</div>
</td>
<td class='arc'><pre>
>(zerotable (pr "hello"))
<span class="stdout"><table border=0 cellpadding=0 cellspacing=0>hello</table>
</span></pre>
<hr/>
<table border=0 cellpadding=0 cellspacing=0>hello</table>
</td></tr>
<tr>
<td class='arc'><a name='tr'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>tr</span> <span class='args'>[body ...]</span>
<div class='desc'>Prints <code>body</code> in a <code>tr</code> tag.</div>
</td>
<td class='arc'><pre>
>(prn "hello")
<span class="stdout">hello
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='row'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>row</span> <span class='args'>[arg ...]</span>
<div class='desc'>Prints a table row. Prints a <code>td</code> tag around each <code>arg</code>, and a <code>tr</code> tag around the whole output.</div>
</td>
<td class='arc'><pre>
>(row 1 "a" 'b)
<span class="stdout"><tr><td>1</td><td>a</td><td>b</td></tr>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='prrow'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>prrow</span> <span class='args'>[arg ...]</span>
<div class='desc'>Prints a <code>td</code> tag around each <code>arg</code>, and a <code>tr</code> tag around the whole output. Each <code>arg</code> that is a number is right-justified.</div>
</td>
<td class='arc'><pre>
>(prrow 1 "a" 'b)
<span class="stdout"><tr><td align=right>1</td><td>a</td><td>b</td></tr>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='spacerow'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>spacerow</span> <span class='args'>h</span>
<div class='desc'>Prints a spacer table row of height <code>h</code>.</div>
</td>
<td class='arc'><pre>
>(spacerow 10)
<span class="stdout"><tr style="height:10px"></tr>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='spanrow'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>spanrow</span> <span class='args'>colspan [body ...]</span>
<div class='desc'>Prints <code>body</code> in a <code>tr</code> and <code>td</code> tag with the given <code>colspan</code>.</div>
</td>
<td class='arc'><pre>
>(spanrow 3 (pr "hello"))
<span class="stdout"><tr><td colspan=3>hello</td></tr>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='trtd'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>trtd</span> <span class='args'>[body ...]</span>
<div class='desc'>Prints <code>body</code> in <code>tr</code> and <code>td</code> tags. <code>body</code> can be atoms.</div>
</td>
<td class='arc'><pre>
>(trtd (prn "hello"))
<span class="stdout"><tr><td>hello
</td></tr>
</span></pre>
<pre>
>(trtd "hello " "world")
<span class="stdout"><tr><td>hello world</td></tr>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='td'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>td</span> <span class='args'>[body ...]</span>
<div class='desc'>Prints <code>body</code> in a <code>td</code> tag. <code>body</code> can be atoms.</div>
</td>
<td class='arc'><pre>
>(td (prn "hello"))
<span class="stdout"><td>hello
</td>
</span></pre>
<pre>
>(td "hello " "world")
<span class="stdout"><td>hello world</td>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='tdr'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>tdr</span> <span class='args'>[body ...]</span>
<div class='desc'>Prints <code>body</code> in a <code>td</code> tag with alignment set to the right. <code>body</code> can be atoms. Renamed from tdright in arc3.</div>
</td>
<td class='arc'><pre>
>(tdr (prn "hello"))
<span class="stdout"><td align=right>hello
</td>
</span></pre>
<pre>
>(tdright "world")
<span class="stdout">Error: _tdright: undefined;
cannot reference an identifier
before its definition
in module: top-level
internal name
: _tdright
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='tdcolor'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>tdcolor</span> <span class='args'>color [body ...]</span>
<div class='desc'>Prints <code>body</code> in a <code>td</code> tag with the specified <code>bgcolor</code>. <code>body</code> can be atoms.</div>
</td>
<td class='arc'><pre>
>(tdcolor orange (prn 1))
<span class="stdout"><td bgcolor=#ff6600>1
</td>
</span></pre>
<pre>
>(tdcolor orange 1 "world")
<span class="stdout"><td bgcolor=#ff6600>1world</td>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='cellpr'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>cellpr</span> <span class='args'>content</span>
<div class='desc'>Prints content or &nbsp; if the content is <code>nil</code></div>
</td>
<td class='arc'><pre>
>(cellpr 42)
<span class="stdout">42
</span></pre>
<pre>
>(cellpr nil)
<span class="stdout">&nbsp;
</span></pre>
</td></tr>
</table>
<h2>Forms</h2>
<p><table class='arc'>
<tr>
<td class='arc'><a name='form'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>form</span> <span class='args'>action [body ...]</span>
<div class='desc'>Prints <code>body</code> in a <code>form</code> tag.</div>
</td>
<td class='arc'><pre>
>(form "http://arcfn.com" (pr "hello"))
<span class="stdout"><form method=post action="http://arcfn.com">hello</form>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='submit'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>submit</span> <span class='args'>[value]</span>
<div class='desc'>Prints a <code>submit</code> tag.</div>
</td>
<td class='arc'><pre>
>(submit "hello")
<span class="stdout"><input type=submit value="hello">
</span></pre>
<hr/>
<input type=submit value="hello">
</td></tr>
<tr>
<td class='arc'><a name='but'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>but</span> <span class='args'>[value [name]]</span>
<div class='desc'>Prints a <code>submit</code> button tag.</div>
</td>
<td class='arc'><pre>
>(but "foo" "bar")
<span class="stdout"><input type=submit name="bar" value="foo">
</span></pre>
<hr/>
<input type=submit name="bar" value="foo">
</td></tr>
<tr>
<td class='arc'><a name='buts'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>buts</span> <span class='args'>name [text ...]</span>
<div class='desc'>Prints multiple <code>submit</code> button tags, one for each <code>text</code>.</div>
</td>
<td class='arc'><pre>
>(buts "foo" "bar" "baz")
<span class="stdout"><input type=submit name="foo" value="bar">
<input type=submit name="foo" value="baz">
</span></pre>
<hr/>
<input type=submit name="foo" value="bar"> <input type=submit name="foo" value="baz">
</td></tr>
<tr>
<td class='arc'><a name='textarea'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>textarea</span> <span class='args'>name rows cols [body ...]</span>
<div class='desc'>Prints <code>body</code> in a <code>textarea</code> tag.</div>
</td>
<td class='arc'><pre>
>(textarea "foo" 1 40 (pr "Contents"))
<span class="stdout"><textarea name="foo" rows=1 cols=40>Contents</textarea>
</span></pre>
<hr/>
<textarea name="foo" rows=1 cols=40>Contents</textarea>
</td></tr>
<tr>
<td class='arc'><a name='menu'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>menu</span> <span class='args'>name itemlist [sel]</span>
<div class='desc'>Prints a menu with <code>select</code> and </code>option</code>. Each element of <code>itemlist</code> becomes an option. If <code>sel</code> is an item in <code>itemlist</code>, that item is marked as selected.</div>
</td>
<td class='arc'><pre>
>(menu "foo" '(item1 item2 item3) 'item2)
<span class="stdout"><select name="foo"><option>item1</option>
<option selected>item2</option><option>item3</option>
</select>
</span></pre>
<hr/>
<select name="foo"><option>item1</option><option selected>item2</option><option>item3</option></select>
</td></tr>
<tr>
<td class='arc'><a name='input'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>input</span> <span class='args'>name [val [size ]]</span>
<div class='desc'>Prints an <code>input</code> tag.</div>
</td>
<td class='arc'><pre>
>(input "foo" "bar" 10)
<span class="stdout"><input type=text name="foo" value="bar" size=10>
</span></pre>
<hr/>
<input type=text name="foo" value="bar" size=10>
</td></tr>
<tr>
<td class='arc'><a name='inputs'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>inputs</span> <span class='args'>[name label size value ...]</span>
<div class='desc'>Prints a table of labelled text rows. If <code>size</code> is an atom, a text input of the specified size is generated. If <code>size</code> is a list <code>(rows cols)</code>, then a textarea of the specified size is generated. If the label is <code>password</code> a password input is generated. The label is followed by a colon.</div>
</td>
<td class='arc'><pre>
>(inputs i1 "Foo" 10 "contents"
p1 password 10 "pw"
i2 "Bar" '(2 5) "stuff")
<span class="stdout"><table border=0><tr><td>Foo:</td><td>
<input type=text name="i1" size=10 value="contents"></td>
</tr><tr><td>password:</td><td>
<input type=password name="p1" size=10 value="pw"></td></tr>
<tr><td>Bar:</td><td><textarea name="i2" rows=2 cols=5>stuff
</textarea></td></tr></table>
</span></pre>
<hr/>
<table border=0><tr><td>Foo:</td><td><input type=text name="i1" size=10 value="contents"></td></tr><tr><td>password:</td><td><input type=password name="p1" size=10 value="pw"></td></tr><tr><td>Bar:</td><td><textarea name="i2" rows=2 cols=5>stuff</textarea></td></tr></table>
</td></tr>
<tr>
<td class='arc'><a name='single-input'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>single-input</span> <span class='args'>label name size buttontext [password]</span>
<div class='desc'>Prints a text or password input prefixed with <code>label</code> followed by a submit button.</div>
</td>
<td class='arc'><pre>
>(single-input "Secret" 'i1 5 "Submit" 'password)
<span class="stdout">Secret<input type=password name="i1" size=5>
<input type=submit value="Submit">
</span></pre>
<hr/>
Secret<input type=password name="i1" size=5> <input type=submit value="Submit">
</td></tr>
</table>
<h2>Other operations</h2>
<p><table class='arc'>
<tr>
<td class='arc'><a name='attribute'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>attribute</span> <span class='args'>tag attribute f</span>
<div class='desc'>Defines that <code>tag</code> can have <code>attribute</code>. <code>f</code> is on of the <code>op...</code> functions, defining the type of <code>attribute</code>.</div>
</td>
<td class='arc'><pre>
>(attribute a class opsym)
<span class="return">#<procedure: opsym>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='color'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>color</span> <span class='args'>r g b</span>
<div class='desc'>Creates a color object with the specified red, green, and blue components (0 to 255)</div>
</td>
<td class='arc'><pre>
>(color 255 0 128)
<span class="return">#hash((b . 128) (g . 0) (r . 255))
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='hex>color'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>hex>color</span> <span class='args'>str</span>
<div class='desc'>Converts a string of length 6 representing a <a href='http://en.wikipedia.org/wiki/Web_colors#Hex_triplet'>hex triplet</a> into a color object. Returns <code>nil</code> on failure.</div>
</td>
<td class='arc'><pre>
>(hex>color "ff00cc")
<span class="return">#hash((b . 204) (g . 0) (r . 255))
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='gray'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>gray</span> <span class='args'>n</span>
<div class='desc'>Creates a color object representing a gray level. <code>n</code> is between 0 and 255.</div>
</td>
<td class='arc'><pre>
>(gray 100)
<span class="return">#hash((b . 100) (g . 100) (r . 100))
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='hexrep'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>hexrep</span> <span class='args'>color</span>
<div class='desc'>Converts a color object to a hex triplet string.</div>
</td>
<td class='arc'><pre>
>(hexrep orange)
<span class="return">"ff6600"
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='dehex'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>dehex</span> <span class='args'>str</span>
<div class='desc'>Converts <code>str</code> from hex to integer. Returns <code>nil</code> if the conversion fails.</div>
</td>
<td class='arc'><pre>
>(dehex "40")
<span class="return">64
</span></pre>
<pre>
>(dehex "0x12")
<span class="return">nil
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='gentag'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>gentag</span> <span class='args'>tag [attribute value ...]</span>
<div class='desc'>Prints the tag.</div>
</td>
<td class='arc'><pre>
>(gentag img src "foo.gif")
<span class="stdout"><img src="foo.gif">
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='tag'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>tag</span> <span class='args'>spec [body ...]</span>
<div class='desc'>Prints <code>body</code> surrounded by the tag specified by <code>spec</code>.</div>
</td>
<td class='arc'><pre>
>(gentag a href "/index.html")
<span class="stdout"><a href="/index.html">
</span></pre>
<hr/>
<a href="/index.html">
<pre>
>(pr "click")
<span class="stdout">click
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='tag-if'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>tag-if</span> <span class='args'>test spec [body ...]</span>
<div class='desc'>If <code>test</code> is true, <code>body</code> is wrapped in the tag <code>spec</code>. Otherwise, <code>body</code> is printed without the tag.</div>
</td>
<td class='arc'><pre>
>(tag-if t (underline) (pr "hi"))
<span class="stdout"><underline>hi</underline>
</span></pre>
<pre>
>(tag-if nil (underline) (pr "hi"))
<span class="stdout">hi
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='pr-escaped'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>pr-escaped</span> <span class='args'>str</span>
<div class='desc'>Prints <code>str</code> with <, >, ", and & HTML-escaped.</div>
</td>
<td class='arc'><pre>
>(pr-escaped "abc< > \" ' &")
<span class="stdout">abc&#60; &#62; &#34; ' &#38;
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='eschtml'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>eschtml</span> <span class='args'>str</span>
<div class='desc'>Returns a string that is <code>str</code> with <, >, ", ', and & HTML-escaped.</div>
</td>
<td class='arc'><pre>
>(eschtml "abc< > \" ' &")
<span class="return">"abc&#60; &#62; &#34; &#39; &#38;"
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='esc<>&'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>esc<>&</span> <span class='args'>str</span>
<div class='desc'>Returns a string that is <code>str</code> with <, >, and & HTML-escaped.</div>
</td>
<td class='arc'><pre>
>(esc<>& "abc< > \" ' &")
<span class="stdout">Error: _esc
<>: undefined;
cannot reference an identifier before its de
finition
in module: top-level
internal name: _esc<>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='cdata'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>cdata</span> <span class='args'>[body ...]</span>
<div class='desc'>Prints <code>body</code> in a CDATA section.</div>
</td>
<td class='arc'><pre>
>(cdata (pr "hello"))
<span class="stdout"><![CDATA[hello]]>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='striptags'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>striptags</span> <span class='args'>str</span>
<div class='desc'>Returns <code>str</code> without tags. Anything between angle brackets is removed.</div>
</td>
<td class='arc'><pre>
>(striptags "abc<foo>def</foo>ghi")
<span class="return">"abcdefghi"
</span></pre>
</td></tr>
</table>
<h2>Internals</h2>
The implementation of HTML handling in Arc centers around the <code>opmeths*</code> table, which maps from a tag and attribute to one of the <code>op...</code> functions. These functions generate the code that generates the HTML to set an attribute.
<p> One Arc design pattern used in the HTML code is to use multiple functions to generate the code, and then use these functions inside macros. This provides a simulation of first-class macros.
<p><table class='arc'>
<tr>
<td class='arc'><a name='opcolor'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>opcolor</span> <span class='args'>attribute color</span>
<div class='desc'>Generates code to assign a color object to an attribute.</div>
</td>
<td class='arc'><pre>
>(opcolor 'bgcolor orange)
<span class="return">(whenlet gs2254 #hash((b . 0) (g . 102) (r . 255)) (pr " bgcolor=#" (hexrep gs2254)))
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='opstring'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>opstring</span> <span class='args'>attribute string</span>
<div class='desc'>Generates code to assign a string to an attribute, if the string is not <code>nil</code>.</div>
</td>
<td class='arc'><pre>
>(opstring 'class "foo")
<span class="return">(aif "foo" (pr " class=\"" it #\"))
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='opnum'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>opnum</span> <span class='args'>attribute num</span>
<div class='desc'>Generates code to assign a number to an attribute, if <code>num</code> is not <code>nil</code>.</div>
</td>
<td class='arc'><pre>
>(opnum 'width 42)
<span class="return">(aif 42 (pr " width=" it))
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='opsym'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>opsym</span> <span class='args'>attribute val</span>
<div class='desc'>Generates code to assign a value to an attribute.</div>
</td>
<td class='arc'><pre>
>(opsym 'width 42)
<span class="return">(pr " width=" 42)
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='opesc'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>opesc</span> <span class='args'>attribute val</span>
<div class='desc'>Generates code to assign a quoted value to an attribute. If <code>val</code> is a string, it is escaped with <code>pr-escaped</code>.</div>
</td>
<td class='arc'><pre>
>(opesc 'foo 'val)
<span class="return">(awhen val (pr " foo=\"") (if (isa it (quote string)) (pr-escaped it) (pr it)) (pr #\"))
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='opsel'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>opsel</span> <span class='args'>attribute val</span>
<div class='desc'>Generates code to set <code>attribute</code> to <code>selected</code> if <code>val</code> is true.</div>
</td>
<td class='arc'><pre>
>(opsel 'foo 'bar)
<span class="return">(if bar (pr " selected"))
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='start-tag'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>start-tag</span> <span class='args'>spec</span>
<div class='desc'>Generates code to start a tag.</div>
</td>
<td class='arc'><pre>
>(start-tag '(a href foo))
<span class="return">(do (pr "<a") (aif foo (pr " href=\"" it #\")) (pr ">"))
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='end-tag'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>end-tag</span> <span class='args'>spec</span>
<div class='desc'>Generates code to end a tag.</div>
</td>
<td class='arc'><pre>
>(end-tag '(a href foo))
<span class="return">(pr "</a>")
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='tag-options'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>tag-options</span> <span class='args'>tag options</span>
<div class='desc'>Generates code to assign values to attributes. <code>options</code> is a list of attribute/value pairs. The allowable attributes are defined by <code>opmeth</code>, and <code>style</code> is allowed for all tags.</div>
</td>
<td class='arc'><pre>
>(tag-options 'td '((bgcolor red) (width 42)))
<span class="return">((whenlet gs2255 red (pr " bgcolor=#" (hexrep gs2255))) " width=42")
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='opmeths*'></a>
<img src='var.gif' title='Variable'/>
<span class='op'>opmeths*</span> <span class='args'></span>
<div class='desc'>Table indexed by list of tag and attribute.</div>
</td>
<td class='arc'><pre>
>(opmeths* '(a href))
<span class="return">#<procedure: opstring>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='opmeth'></a>
<img src='macro.gif' title='Macro'/>
<span class='op'>opmeth</span> <span class='args'>tag attr</span>
<div class='desc'>Looks up the HTML tag and attribute in <code>opmeths*</code></div>
</td>
<td class='arc'><pre>
>(opmeth 'a 'href)
<span class="return">#<procedure: opstring>
</span></pre>
</td></tr>
</table>
<p>
Copyright 2008 Ken Shirriff.
</body>
</html>