| > Both these data structures are different from the DOM tree. In the case of S-expressions that is true. In the case of HTML it may or may not be true. It depends on how the HTML parser is implemented. There is a "natural" mapping of HTML onto a parse tree that is different from the DOM, but that is not part of the standard (AFAIK). > Can CL-WHO generate HTML that matches that? Yes, though native Common Lisp does not provide c-like string escapes so putting in newlines is a little awkward. You could, of course, bring in a string interpolation library, but here's how you can do it without that: ? (defun nl () (who (fmt "~%"))) ; NL = NewLine
NL
? (defun nli () (who (fmt "~% "))) ; NLI = NewLine + Indent
NLI
? (princ (html (:pre (nli) (:span "one" (nli)) (nli) (:br (nli) (:span "two") (nl)))))
<pre>
<span>one
</span>
<br>
<span>two</span>
</br></pre>
Or you could do this: (html (:pre "
<span>one
</span>
<br>
<span>two</span>
<br />
"))
which looks like cheating but is actually closer to the spirit of the original.The PRE tag is really weird because it actually changes the way things inside it are parsed. You can actually implement that in Lisp too via reader macros. CL-WHO doesn't support that out of the box, but it's not hard. I can't imagine anyone actually wanting to do that, though. The PRE tag is for presenting pre-formatted text without changing its appearance, so embedding other tags inside it is kinda perverse. [EDIT: I was wrong about this. See below.] |
pre provides the simplified line breaking and usually a monospaced font. However, tags are available to do whatever else.
A major example is that the Vim editor uses pre for formatting syntax colored code to HTML (when you do that with :TOhtml).
The output is a pre block containing various span elements which are styled with CSS.
BTW where in the HTML spec does it say that the interior of pre is parsed differently?
If we are parsing HTML (to Lisp objects or whatever), we should preserve the exact whitespace. The reverse generation should regurgitate the original whitespace.
If we take the license to eliminate newlines, then we ruin pre. The fix is simply not to do that.