[Checkins] SVN: z3c.pt/trunk/ Add entity definitions for standard HTML entity names.

Malthe Borch mborch at gmail.com
Tue Sep 2 09:12:15 EDT 2008


Log message for revision 90702:
  Add entity definitions for standard HTML entity names.

Changed:
  U   z3c.pt/trunk/CHANGES.txt
  U   z3c.pt/trunk/src/z3c/pt/translation.py

-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt	2008-09-02 13:10:26 UTC (rev 90701)
+++ z3c.pt/trunk/CHANGES.txt	2008-09-02 13:12:15 UTC (rev 90702)
@@ -15,6 +15,8 @@
 
   Features
 
+- Allow standard HTML entities. [malthe]
+  
 - Added compiler option to specify an implicit doctype; this is
   currently used by the template classes to let the loose XHTML
   doctype be the default. [malthe]

Modified: z3c.pt/trunk/src/z3c/pt/translation.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/translation.py	2008-09-02 13:10:26 UTC (rev 90701)
+++ z3c.pt/trunk/src/z3c/pt/translation.py	2008-09-02 13:12:15 UTC (rev 90702)
@@ -10,7 +10,8 @@
 import config
 import etree
 import marshal
-    
+import htmlentitydefs
+
 class Node(object):
     """Element translation class.
 
@@ -447,8 +448,15 @@
         # the document source
         no_doctype_declaration = '<!DOCTYPE' not in body
         if implicit_doctype and no_doctype_declaration:
+            # munge entities into declaration
+            entities = "".join((
+                '<!ENTITY %s "&#%s;">' % (name, text) for (name, text) in \
+                htmlentitydefs.name2codepoint.items()))
+            implicit_doctype = implicit_doctype[:-1] + '  [ %s ]>' % entities
+
+            # prepend to body
             body = implicit_doctype + "\n" + body
-            
+
         self.root, parsed_doctype = parser.parse(body)
 
         if explicit_doctype is not None:



More information about the Checkins mailing list