[Commits] python.it commit r193 - www/trunk/scripts/ht2html

commit a svn.python.it commit a svn.python.it
Ven 14 Lug 2006 13:05:59 CEST


Author: manlio
Date: Fri Jul 14 13:05:57 2006
New Revision: 193

Added:
   www/trunk/scripts/ht2html/htvalidate.py
Modified:
   www/trunk/scripts/ht2html/PDONewGenerator.py
Log:
supporto per XHTML 1.0 Strict

Modified: www/trunk/scripts/ht2html/PDONewGenerator.py
==============================================================================
--- www/trunk/scripts/ht2html/PDONewGenerator.py	(original)
+++ www/trunk/scripts/ht2html/PDONewGenerator.py	Fri Jul 14 13:05:57 2006
@@ -5,6 +5,9 @@
 Manlio Perillo <manlio.perillo a gmail.com> (reST support)
 
 $Id$
+
+TODO: aggiungere link a validatore XHTML w3.org
+      agiungere credits su chi offre hosting e l'autore dello stile
 """
 
 import os
@@ -168,8 +171,9 @@
         # XXX TODO use XHTML instead?
         """Return the HTML <head> stuff."""
         print '''\
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-%(xmlstyle)s<html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+%(xmlstyle)s<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
 <!-- THIS PAGE IS AUTOMATICALLY GENERATED.  DO NOT EDIT. -->
 <!-- %(time)s -->
 <!-- USING HT2HTML %(version)s -->

Added: www/trunk/scripts/ht2html/htvalidate.py
==============================================================================
--- (empty file)
+++ www/trunk/scripts/ht2html/htvalidate.py	Fri Jul 14 13:05:57 2006
@@ -0,0 +1,54 @@
+"""Validate an ht file.
+
+Author: Manlio Perillo
+"""
+
+import sys
+import os
+import email
+
+doctypes = {
+    'strict' : """<!DOCTYPE html 
+    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">""",
+
+    'transitional': """<!DOCTYPE html 
+    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">"""
+}
+
+
+template = """<?xml version="1.0" encoding="ISO-8859-1"?>
+%s
+<html xmlns="http://www.w3.org/1999/xhtml" 
+      xml:lang="it" lang="it">
+   <head>
+      <title>%s</title>
+   </head>
+   <body>%s</body>
+</html>
+"""
+    
+cmd = "xmllint --noout --valid --loaddtd -"
+
+ht = email.message_from_file(file(sys.argv[1]))
+
+# XXX TODO da riga di comando
+doctype = doctypes['strict']
+title = ht.get('Title', '')
+body = ht.get_payload()
+
+doc = template % (doctype, title, body)
+
+fpin, fpout = os.popen4(cmd)
+fpin.write(doc)
+fpin.close()
+
+print fpout.read()
+
+ret = fpout.close()
+if ret is not None:
+    print "Document not valid"
+
+sys.exit(ret or 0) # XXX
+


Maggiori informazioni sulla lista Commits