Opened 18 years ago
Last modified 12 years ago
#104 new enhancement
Emitting CDATA sections
Reported by: | doug@… | Owned by: | cmlenz |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | Template processing | Version: | 0.3.6 |
Keywords: | CDATA | Cc: |
Description
I'm producing some XML using Genshi, and I need to be able to emit CDATA sections. Using CDATA input means that the py: tags are not processed inside the CDATA sections (which makes perfect sense), but I needed this to work.
I couldn't find anything in Genshi to support doing this, so I hacked up this horrible kludge:
from genshi.builder import Fragment from genshi.core import START_CDATA, END_CDATA class CDataStart(Fragment): def _generate(self): yield START_CDATA, None, None class CDataEnd(Fragment): def _generate(self): yield END_CDATA, None, None
I used instances of these in the template, and it seemed to work ok.
I don't necessarily want you to include this gruesome functionality, but I think the use case is valid at least. I imagine you might have a less horrible solution.
Change History (4)
comment:1 Changed 18 years ago by oliver.cope@…
comment:2 Changed 18 years ago by cmlenz
- Component changed from General to Template processing
- Milestone 0.4 deleted
I don't have a bright idea here either, so this'll have to wait until someone comes up with an acceptable solution.
comment:3 Changed 15 years ago by Carsten Klein <carsten.klein@…>
Please consider escaping <py: statements by <py:
That way, your genshi statements will not be evaluated by the engine.
comment:4 Changed 15 years ago by Carsten Klein <carsten.klein@…>
see also the initiative to support pluggable directives libraries in WorkInProgress/PluggableDirectivesLibraries and ticket #395 thereof.
Hi Doug,
I ran into this one too and found a different solution. ${} substitutions are still made in CDATA sections and if necessary these can be combined with a py:def elsewhere in the template to give you access to the full range of py: attributes, eg:
Not sure this counts as 'less horrible' though -- maybe just 'differently horrible'? ;o)