-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhtml0.html
69 lines (69 loc) · 4.68 KB
/
html0.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
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>