Edgewall Software

Ticket #104 (new enhancement)

Opened 8 years ago

Last modified 3 years ago

Emitting CDATA sections

Reported by: doug@… Owned by: cmlenz
Priority: minor Milestone:
Component: Template processing Version: 0.3.6
Keywords: CDATA Cc:


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

Changed 8 years ago by oliver.cope@…

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>

Not sure this counts as 'less horrible' though -- maybe just 'differently horrible'? ;o)

Changed 8 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.

Changed 5 years ago by Carsten Klein <carsten.klein@…>

Please consider escaping <py: statements by &lt;py:

That way, your genshi statements will not be evaluated by the engine.

Changed 5 years ago by Carsten Klein <carsten.klein@…>

see also the initiative to support pluggable directives libraries in WorkInProgress/PluggableDirectivesLibraries and ticket #395 thereof.

Add/Change #104 (Emitting CDATA sections)


E-mail address and user name can be saved in the Preferences.

Change Properties
<Author field>
as new
as The resolution will be set. Next status will be 'closed'
to The owner will change from cmlenz. Next status will be 'new'
The owner will change from cmlenz to anonymous. Next status will be 'assigned'
Note: See TracTickets for help on using tickets.