I'm using PyRSS2Gen to generate an RSS feed. I've succeeded in extending it to add an extra element to each item in the RSS feed:
class FullRSSItem(PyRSS2Gen.RSSItem):
def __init__(self, **kwargs):开发者_如何转开发
if 'content' in kwargs:
self.content = kwargs['content']
del kwargs['content']
else:
self.content = None
PyRSS2Gen.RSSItem.__init__(self, **kwargs)
def publish_extensions(self, handler):
PyRSS2Gen._opt_element(handler, "content:encoded", '<![CDATA[' + self.content + ']]>')
However, self.content contains HTML tags and all of the angled brackets (including those in the <![CDATA part) are translated into < and > when the feed file is generated.
How do I add an extra RSS item element that contains HTML using PyRSS2Gen?
I eventually ditched the idea of using the CDATA wrapper and just had the full text be encoded. Seems to work.
精彩评论