Opened 19 years ago
Last modified 13 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 19 years ago by oliver.cope@…
comment:2 Changed 19 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 16 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:
<html xmlns:py="http://genshi.edgewall.org/"> <div py:def="foo()"> <span py:content="1 + 2"></span> </div> <script><![CDATA[ ${foo()} ]]></script> </html>Not sure this counts as 'less horrible' though -- maybe just 'differently horrible'? ;o)