For an example, see htout.
For the more general case, see XML.
I was quite interested in something like this, as a toy for generating HTML (either by preprocessing or some CGI hack). I was considering writing a minimal Lisp interpretter in Perl .. oh the putrid irony! I'm a Lisp newbie who suspects that a Lisp-like language would be ideal for the next project.
(html (head (title "Foo page")
(meta (@name "description") (@content "Pointless example page")))
(body (@background "ugly-image.gif")
(h1 "Foo page")
"The text is irrelevant"
(hr)
(boilerplate)))
Presumably one reads the @ributes like so.
In the Araneida you would use something like
((p :align "center" :class "myclass") "The paragraph")
to specify attributes i.e. either a symbol of a cons of a symbol and a property list can be used to represent the element. This is much easier than the approach you mention below.
I believe what I've done amounts to banning "evaluation of sexpr to find out what tag to use", so I can't express what would in perl be $tag = $cond ? "b" : "em".
(html (head (title Foo page)
(meta ((name description) (content Pointless example page))))
(body ((background ugly-image.gif))
(h1 Foo page)
The text is irrelevant
(hr)
(boilerplate)))
Oh yeah and I ditched the annoying quotes. Since I was going to implement a crusty list reader, might as well specialise it.
Boilerplate? Well it looks like a server-side include.
You don't say whether this is code or data. The function in Araneida uses a representation like your second example above, but as data. We use backquote and comma to splice expressions into the html.
Um ... both? It's data to start with. If it were mine or generated by code I trusted, I would just execute it to get back the large string containing text/html. If it may be hostile I would have to write a mini lisp interpretter (yes? or am I deluded?).
You can actually do much more interesting things using the s-exp approach. You can create you own elements and attach functions which create html based on the content e.g. I use an 'MCQ element to present multiple choice questions in forms. I also attach preprocessing functions to different symbols to e.g. generate required images (such as equations) for the web page as a side effect. I am also assigning functioanlity to convert the markup to latex for creation of pdf files on the fly i.e. you don't have to limit yourself to HTML - the markup can match your problem space and them be mapped to html, or latex, or whatever. (JARW)
Bonus points for finding a really horrible way to enforce the DTD's rules. Remapping symbols to (raise "You can't put that there") ?
Here's a lispy XML validator: xml-psychiatrist
This page is linked from: araneida Cut and shut heredocs in lisp HTML-TEMPLATE Lisp Markup Languages
CLiki pages can be edited by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively