开发者

How do I create an extra RSS item element that contains HTML using PyRSS2Gen?

开发者 https://www.devze.com 2022-12-16 15:56 出处:网络
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:

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 &lt; and &gt; 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消