Commits

Łukasz Fidosz  committed 0f7476e

added escaping html and putting xhtml into namespace

  • Participants
  • Parent commits de6ff28

Comments (0)

Files changed (1)

File webhelpers/feedgenerator.py

 
 import re
 import datetime
-from webhelpers.util import SimplerXMLGenerator, iri_to_uri
+from webhelpers.util import SimplerXMLGenerator, iri_to_uri, html_escape
 
 #### The following code comes from ``django.utils.feedgenerator`` ####
 
     # Spec: http://atompub.org/2005/07/11/draft-ietf-atompub-format-10.html
     mime_type = 'application/atom+xml'
     ns = u"http://www.w3.org/2005/Atom"
+    xhtml_namespace = 'http://www.w3.org/1999/xhtml'
+
+    def __init__(self, title, link, description, language=None, author_email=None,
+            author_name=None, author_link=None, subtitle=None, categories=None,
+            feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, 
+            contains_xhtml=False, **kwargs):
+
+        super(Atom1Feed, self).__init__(title, link, description, language,
+                                        author_email, author_name, author_link,
+                                        subtitle, categories, feed_url,
+                                        feed_copyright, feed_guid, ttl,
+                                        contains_xhtml=contains_xhtml, **kwargs)
+
 
     def write(self, outfile, encoding):
         handler = SimplerXMLGenerator(outfile, encoding)
 
         # Summary.
         if item['description'] is not None:
-            handler.addQuickElement(u"summary", item['description'], {u"type": u"html"})
+            if not self.feed['contains_xhtml']:
+                summary = html_escape(item['description'])
+                handler.addQuickElement(u"summary", summary, {u"type": u"html"})
+            else:
+                handler.startElement('summary', {'type': 'xhtml'})
+                handler.startPrefixMapping(None, self.xhtml_namespace)
+                handler.startElementNS((self.xhtml_namespace, 'div'), None, {})
+                handler.characters(item['description'])
+                handler.endElementNS((self.xhtml_namespace, 'div'), None)
+                handler.endPrefixMapping(None)
+                handler.endElement('summary')
 
         # Enclosure.
         if item['enclosure'] is not None: