[Checkins] SVN: Sandbox/malthe/chameleon.core/ Avoid self-closing tags that are not allowed in transitional HTML.

Malthe Borch mborch at gmail.com
Mon Nov 17 09:13:27 EST 2008


Log message for revision 93048:
  Avoid self-closing tags that are not allowed in transitional HTML.

Changed:
  U   Sandbox/malthe/chameleon.core/CHANGES.txt
  U   Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py
  U   Sandbox/malthe/chameleon.core/src/chameleon/core/translation.txt

-=-
Modified: Sandbox/malthe/chameleon.core/CHANGES.txt
===================================================================
--- Sandbox/malthe/chameleon.core/CHANGES.txt	2008-11-17 13:40:15 UTC (rev 93047)
+++ Sandbox/malthe/chameleon.core/CHANGES.txt	2008-11-17 14:13:26 UTC (rev 93048)
@@ -4,6 +4,9 @@
 HEAD
 ~~~~
 
+- Avoid self-closing tags that are not allowed in transitional
+  HTML. [malthe]
+
 - Use custom serialization method to serialize static default
   translation blocks; we can't rely on `lxml` for sane
   output. [malthe]

Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py	2008-11-17 13:40:15 UTC (rev 93047)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py	2008-11-17 14:13:26 UTC (rev 93048)
@@ -586,7 +586,22 @@
             self.doctype = explicit_doctype
         elif parsed_doctype and not no_doctype_declaration:
             self.doctype = parsed_doctype
-            
+
+        # limit self-closing tags to the allowed subset for templates
+        # with a non-XML compliant document type (non-strict)
+        ldoctype = (self.doctype or implicit_doctype or "").lower()
+        if 'html' in ldoctype and 'strict' not in ldoctype:
+            for element in self.root.getiterator():
+                try:
+                    tag = element.tag.split('}')[-1]
+                except AttributeError:
+                    continue
+
+                if element.text is None and tag not in (
+                    'area', 'base', 'basefont', 'br',
+                    'hr', 'input', 'img', 'link', 'meta'):
+                    element.text = ""
+                    
         self.parser = parser
 
         if utils.coerces_gracefully(encoding):

Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/translation.txt
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/translation.txt	2008-11-17 13:40:15 UTC (rev 93047)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/translation.txt	2008-11-17 14:13:26 UTC (rev 93048)
@@ -82,12 +82,12 @@
   ...   Hello   World!
   ...   <a href="localhost" title="Singing &amp; Dancing"
   ...   >&rarr;</a>
-  ...   <span class="&rarr;" />
+  ...   <span class="&rarr;"></span>
   ... </html>""")
     <html>
       Hello &nbsp; World!
       <a href="localhost" title="Singing &amp; Dancing">&rarr;</a>
-      <span class="&rarr;" />
+      <span class="&rarr;"></span>
     </html>
 
 :: Processing instructions output literally



More information about the Checkins mailing list