One of my needs is to place style information into HTML. My
application uses wxPython which in turn uses wxWidgets. The
wxWidgets HTML viewer does not support style sheets, or the
class attribute. This is actually the hard part. The templating
itself is actually easy.
This is what I do at the moment:
- First pass over the template using xyaptu from the Python
cookbook. This is an example template:
In particular note that I do use class attributes which
are ignored by the wxWidgets HTML viewer.
- Do a second pass using HTMLParser.HTMLParser which generates a
tree of the document structure (it also requires the HTML to
be perfect with *all* tags having matching closes. I then have
a file that defines styles.
That says where to inject style information. The dict says what
attributes to add to the tag the class was found in (the '' case)
and then also lists how tags contained within should be modified.
Later down there are also tags that get added.
So I have a fairly big mess. I am having to simulate style-sheets,
produce 100% correct HTML and also have various value formatting
functions all over the place.
I actually like PHP's Smarty the best, mainly for the modifiers
and being able to do things like capture.