﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15936	Syndication: Turning off autoescape (content:encoded)	Brant Steen <brant.steen@…>	nobody	"A very common element to pull into an RSS feed is the content:encoded element. In a blog, for example, it allows you to put a full entry into your RSS feed, including the HTML in that entry (headings, paragraphs, lists, whatnot).

I couldn't find a way to get this element to work, given the current contrib.syndication module. I would do this:

{{{
class ExtendedRSSFeed(feedgenerator.Rss201rev2Feed):
    """"""
    Create a type of RSS feed that has content:encoded elements.
    """"""
    def root_attributes(self):
        attrs = super(ExtendedRSSFeed, self).root_attributes()
        attrs['xmlns:content'] = 'http://purl.org/rss/1.0/modules/content/'
        return attrs
    
    def add_item_elements(self, handler, item):
        super(ExtendedRSSFeed, self).add_item_elements(handler, item)
        handler.addQuickElement(u'content:encoded', item['content_encoded'])

...

class TheFeed(Feed):
    feed_type = ExtendedRSSFeed

    ....

    def item_extra_kwargs(self, item):
        return {'content_encoded': self.item_content_encoded(item)}
    
    def item_content_encoded(self, item):
        return ""<![CDATA[%s]]>"" % item.content    
}}}

But that would generate a feed with all of the HTML bits autoescaped... even if I put an {% autoescape off %} block in the template where the content:encoded was being pulled from. So, instead of being able to stick html tags inside the CDATA, I would just end up with a lot of &lt;h1&gt; stuff.

After drilling in and finding the SimplerXMLGenerator, it seemed like the ability to turn off autoescaping could be done at this point, without breaking anyone's current implementations (see patch). Thus, the only change to the above example becomes this:


{{{
class ExtendedRSSFeed(feedgenerator.Rss201rev2Feed):
    """"""
    Create a type of RSS feed that has content:encoded elements.
    """"""
    def root_attributes(self):
        attrs = super(ExtendedRSSFeed, self).root_attributes()
        attrs['xmlns:content'] = 'http://purl.org/rss/1.0/modules/content/'
        return attrs
    
    def add_item_elements(self, handler, item):
        super(ExtendedRSSFeed, self).add_item_elements(handler, item)
        handler.addQuickElement(u'content:encoded', item['content_encoded'], escape=False)
}}}

And then content:encoded can be handled through the normal syndication process.

"	New feature	closed	contrib.syndication	1.3	Normal	invalid	syndication, content:encoded		Unreviewed	1	1	1	0	0	0
