Discussion:
Parsing html again
Andrei Stebakov
2008-02-27 17:12:06 UTC
Permalink
When we generate the JavaScript <script> with cl-who we need to put the
empty string at the end of the command to have the closing </script> tag
like so:
(with-html-output-to-string (*standard-output* nil :prologue nil :indent
nil)
(:html
(:head (:title "Temporary page")
(:script :language "JavaScript" :src "/test/scripts.js"
:type "text/javascript" ""))))
It will generate:
<html><head><title>Temporary page</title><script language='JavaScript'
src='/test/scripts.js' type='text/javascript'></script></head></html>

Now if we parse the html with html-parse:parse-html command and convert it
back to the string with tree-to-string (here is the
thread<http://common-lisp.net/pipermail/cl-who-devel/2007-November/000109.html>about
this command) we'll get the broken <script> tag without the closing
</script>
It's because html-parse:parse-html will produce
((:HTML
(:HEAD (:TITLE "Temporary page")
((:SCRIPT :LANGUAGE "JavaScript" :SRC "/test/scripts.js" :TYPE
"text/javascript")))))
Note, that there is no "" at the end of (:script) anymore.

My question is where this problem should be fixed at html-parse:parse-html
level so that parse-html would insert the "" when it finds the <script> tag,
or there is a clean way to do it in cl-who?
Victor Kryukov
2008-02-27 18:28:19 UTC
Permalink
When we generate the JavaScript <script> with cl-who we need to put the empty
(with-html-output-to-string (*standard-output* nil :prologue nil :indent nil)
(:html
(:head (:title "Temporary page")
(:script :language "JavaScript" :src "/test/scripts.js"
:type "text/javascript" ""))))
<html><head><title>Temporary page</title><script language='JavaScript' src='/
test/scripts.js' type='text/javascript'></script></head></html>
That strange. On my system, both for SBCL and CLisp,

WHO> (with-html-output-to-string (*standard-output* nil :prologue nil :indent nil)
(:html
(:head (:title "Temporary page")
(:script :language "JavaScript" :src "/test/scripts.js"
:type "text/javascript"))))
"<html><head><title>Temporary page</title><script language='JavaScript' src='/test/scripts.js' type='text/javascript'></script></head></html>"

If you insist on using non-documented features, like tree-to-string, read
the sources (although the following two variables are documented in
the docs[1]).

WHO> (documentation '*html-empty-tags* 'variable)
"The list of HTML tags that should be output as empty tags.
See *HTML-EMPTY-TAG-AWARE-P*."
WHO> (documentation '*html-empty-tag-aware-p* 'variable)
"Set this to NIL to if you want to use CL-WHO as a strict XML
generator. Otherwise, CL-WHO will only write empty tags listed
in *HTML-EMPTY-TAGS* as <tag/> (XHTML mode) or <tag> (SGML
mode). For all other tags, it will always generate
<tag></tag>."
WHO> (member :script *html-empty-tags*)
NIL

[1] http://www.weitz.de/cl-who/#*html-empty-tag-aware-p*

Regards,
Victor.
--
My blog: http://macrodefinition.blogspot.com
Loading...