HTML -> HTMLGen (or similiar)

Walter Dörwald walter at livinglogic.de
Thu Apr 10 04:21:52 EDT 2003


VanL wrote:

> Hello,
> 
> I have a bunch of existing HTML that I need to integrate into a new web 
> app.  I would ideally like to use one of the existing HTML generation 
> systems (HTMLgen, HyperText, any others) but I don't want to have to 
> build up an equivalent representation for the many pages I need to work 
> with.

You can use XIST for that (available from
http://www.livinglogic.de/Python/xist/)

Code looks like this:

=====
from ll.xist import parsers, presenters
e = parsers.parseURL("http://www.python.org/", tidy=True)
print e.repr(presenters.CodePresenter())
=====

This dumps the Python website as an XIST DOM constructor, looking
something like this (with whitespace removed):

ll.xist.xsc.Frag(
    ll.xist.ns.xml.XMLStyleSheet('href="./css/ht2html.css" ..."'),
    ll.xist.ns.html.html(
       xsc.Comment(' THIS PAGE IS AUTOMATICALLY ... '),
       xsc.Comment(' Fri Apr  4 10:59:44 2003 '),
       xsc.Comment(' USING HT2HTML 2.0 '),
       xsc.Comment(' SEE http://ht2html.sf.net '),
       xsc.Comment(' User-specified headers:\nTitle: Python ...'),
       ll.xist.ns.html.head(
          ll.xist.ns.html.title(
             'Python Language Website'
          ),
       ...

You might want to shorten the class names (i.e. removing the
"ll.xist.ns." part). The final output code might look like
this:

from ll.xist import xsc
from ll.xist.ns import xml, html

e = xsc.Frag(
    xml.XML10(),
    html.DocTypeXHTML10transitional(),
    xml.XMLStyleSheet('href="./css/ht2html.css" ..."'),
    html.html(
       xsc.Comment(' THIS PAGE IS AUTOMATICALLY ... '),
       ...
    )
)

print e.asBytes(encoding="utf-8")

Hope that helps!

Bye,
    Walter Dörwald





More information about the Python-list mailing list