[ZPT] playing with stylesheets in ZPT?
Guido van Rossum
guido@digicool.com
Mon, 09 Apr 2001 21:59:14 -0500
Sounds like you've found a good reason for a feature that we
originally considered but decided to throw out: a phase where
arbitrary processing by Python code is allowed. We couldn't figure
out what the interface should be, and which part of the source should
be accessible to the code, whether it should be passed text or a DOM
tree, and whether it should be invoked before or after all parsing.
> At the moment, it's looking like I'm going to have to manually parse the
> ZPT to pick out the <style> tag and its contents. Then create an internal
> list of the <style> tag contents and insert a tal:content statement into
> the ZPT source. The tal:content statement will then look up the appropriate
> <style> tag contents internally and parse/mangle them.
>
> This would be so much easier if I could use the TAL parser rather than
> having to write my own...
Well, how about if you subclass the TALGenerator or TALInterpreter
classes, and slightly modify the PageTemplate product to invoke your
subclasses. Or you could subclass the HTMLTALParser class.
And once you've figured how to do this for your specific case, maybe
we'll be able to provide more general hooks that will be flexible
enough without breaking our processing model. (I'm not trying to make
you do our job, I'm just thinking that since you know exactly what you
need *and* you aren't afraid of experimenting, you'd be able to make
more progress on your own at first.)
I see three good places to intercept processing:
- At parse time.
- At code generation time (this is also at parse time, but logically
later; and while we have separate parsers for XML and HTML, they use
the same code generation backend).
- At interpretation time.
I'm not sure from your example which would be the best phase for your
processing.
(BTW, I think we'll need a name for the intermediate code. I propose
TALcode.)
--Guido van Rossum (home page: http://www.python.org/~guido/)