@@ -95,10 +95,28 @@ def atom_entry(self, feed, extensions=True):
95
95
96
96
if self .__atom_content :
97
97
content = etree .SubElement (entry , 'content' )
98
+ type = self .__atom_content .get ('type' )
98
99
if self .__atom_content .get ('src' ):
99
100
content .attrib ['src' ] = self .__atom_content ['src' ]
100
101
elif self .__atom_content .get ('content' ):
101
- content .text = self .__atom_content .get ('content' )
102
+ # Surround xhtml with a div tag, parse it and embed it
103
+ if type == 'xhtml' :
104
+ content .append (etree .fromstring ('''<div
105
+ xmlns="http://www.w3.org/1999/xhtml">%s</div>''' % \
106
+ self .__atom_content .get ('content' )))
107
+ # Parse XML and embed it
108
+ elif type .endswith ('/xml' ) or type .endswith ('+xml' ):
109
+ content .append (etree .fromstring (self .__atom_content ['content' ]))
110
+ # Emed the text in escaped form
111
+ elif not type or type .startswith ('text' ) or type == 'html' :
112
+ content .text = self .__atom_content .get ('content' )
113
+ # Everything else should be included base64 encoded
114
+ else :
115
+ raise ValueError ('base64 encoded content is not supported at the moment.'
116
+ + 'If you are interested , please file a bug report.' )
117
+ # Add type description of the content
118
+ if type :
119
+ content .attrib ['type' ] = type
102
120
103
121
for l in self .__atom_link or []:
104
122
link = etree .SubElement (entry , 'link' , href = l ['href' ])
@@ -311,7 +329,7 @@ def author(self, author=None, replace=False, **kwargs):
311
329
return self .__atom_author
312
330
313
331
314
- def content (self , content = None , src = None ):
332
+ def content (self , content = None , src = None , type = None ):
315
333
'''Get or set the cntent of the entry which contains or links to the
316
334
complete content of the entry. Content must be provided for ATOM entries
317
335
if there is no alternate link, and should be provided if there is no
@@ -326,6 +344,8 @@ def content(self, content=None, src=None):
326
344
self .__atom_content = {'src' :src }
327
345
elif not content is None :
328
346
self .__atom_content = {'content' :content }
347
+ if not type is None :
348
+ self .__atom_content ['type' ] = type
329
349
self .__rss_description = content
330
350
return self .__atom_content
331
351
0 commit comments