[cl-who-devel] html empty tags
Mac Chan
emailmac at gmail.com
Fri Apr 27 05:19:36 UTC 2007
As you probably know, there are certain html tags that will break the
browser's rendering if they are not paired up properly with a close
tag </tag> even if it's content is empty.
For example, <textarea> and <script> (ie)
Well today I'm bitten by this, where <div id='header' /> messes up
firefox's rendering coupled with some css rules.
Even though I'm awared of how to get around it, sometimes it's rather
hard to spot that with a sea of nested (:div (:div ...)).
This is also a recurring problem for newbie and there were a few
threads regarding this.
Attach is a patch to fix this.
[Special variable]
*html-empty-tag-aware*
Set to NIL to if you want to use cl-who as a strict XML generator.
Otherwise, CL-WHO will only close empty tag defined in
*html-empty-tags* with <tag/> (XHTML mode) or <tag> (SGML mode). For
all other tags, it will always generate <tag></tag>. The default is T.
[Special variable]
*html-empty-tags*
List of html tags that should close by itself. The default values
are '(:base :basefont :br :frame :hr :img :input :isindex :link :meta
:nextid :range :spacer :wbr :audioscope :area :param :keygen :col
:limittext :spot :tab :over :right :left :choose :atop :of)
I'm not sure if anyone is using cl-who to generate XML. If it is, then
you need to set *html-empty-tag-aware* to NIL, because this patch will
change the default behavior (to do the right thing).
Regards,
-- Mac
-------------- next part --------------
Index: who.lisp
===================================================================
--- who.lisp (revision 1123)
+++ who.lisp (working copy)
@@ -58,6 +58,18 @@
(defparameter *empty-tag-end* " />"
"End of an empty tag. Default is XML style.")
+(defparameter *html-empty-tags*
+ '(:base :basefont :br :frame :hr :img :input :isindex :link :meta :nextid :range
+ :spacer :wbr :audioscope :area :param :keygen :col :limittext :spot :tab :over
+ :right :left :choose :atop :of)
+ "List of html tags that should close by itself.")
+
+(defvar *html-empty-tag-aware* T
+ "Set to NIL to if you want to use cl-who as a strict XML
+generator. Otherwise, CL-WHO will only close empty tag defined in
+*html-empty-tags* with <tag/> (XHTML mode) or <tag> (SGML mode). For
+all other tags, it will always generate <tag></tag>.")
+
(eval-when (:compile-toplevel :load-toplevel :execute)
(unless (boundp '+newline+)
(defconstant +newline+ (make-string 1 :initial-element #\Newline)
@@ -275,8 +287,11 @@
(list +newline+ (n-spaces *indent*)))
;; closing tag
(list "</" tag ">"))
- ;; no body, so no closing tag
- (list *empty-tag-end*)))))
+ ;; no body, so no closing tag if not defined in *html-empty-tags*
+ (if (and *html-empty-tag-aware*
+ (member tag *html-empty-tags*))
+ (list *empty-tag-end*)
+ (list ">" "</" tag ">"))))))
(defun apply-to-tree (function test tree)
(declare (optimize speed space))
Index: doc/index.html
===================================================================
--- doc/index.html (revision 1123)
+++ doc/index.html (working copy)
@@ -93,6 +93,8 @@
<li><a href="#show-html-expansion"><code>show-html-expansion</code></a>
<li><a href="#*attribute-quote-char*"><code>*attribute-quote-char*</code></a>
<li><a href="#*prologue*"><code>*prologue*</code></a>
+ <li><a href="#*html-empty-tag-aware*"><code>*html-empty-tag-aware*</code></a>
+ <li><a href="#*html-empty-tags*"><code>*html-empty-tags*</code></a>
<li><a href="#*downcase-tags-p*"><code>*downcase-tags-p*</code></a>
<li><a href="#esc"><code>esc</code></a>
<li><a href="#fmt"><code>fmt</code></a>
@@ -548,6 +550,27 @@
</blockquote>
<p><br>[Special variable]
+<br><a class=none name="*html-empty-tag-aware*"><b>*html-empty-tag-aware*</b></a>
+
+<blockquote><br>
+Set to <code>NIL</code> to if you want to use cl-who as a strict XML
+generator. Otherwise, CL-WHO will only close empty tag defined in
+*html-empty-tags* with <code><tag/></code> (XHTML mode) or <code><tag></code> (SGML mode). For
+all other tags, it will always generate <code><tag></tag></code>. The default is <code>T</code>.
+</blockquote>
+
+<p><br>[Special variable]
+<br><a class=none name="*html-empty-tags*"><b>*html-empty-tags*</b></a>
+
+<blockquote><br>
+List of html tags that should close by itself.
+The default values are
+'(:base :basefont :br :frame :hr :img :input :isindex :link :meta :nextid :range
+ :spacer :wbr :audioscope :area :param :keygen :col :limittext :spot :tab :over
+ :right :left :choose :atop :of)
+</blockquote>
+
+<p><br>[Special variable]
<br><a class=none name="*downcase-tags-p*"><b>*downcase-tags-p*</b></a>
<blockquote><br>
More information about the Cl-who-devel
mailing list