1.1 --- a/macros/SharedContent.py Sat May 11 00:39:47 2013 +0200
1.2 +++ b/macros/SharedContent.py Mon May 13 20:01:29 2013 +0200
1.3 @@ -99,7 +99,7 @@
1.4 feed = StringIO(data)
1.5 _url, content_type, _encoding, _metadata = getCachedResourceMetadata(feed)
1.6
1.7 - if content_type not in ("application/atom+xml", "application/rss+xml"):
1.8 + if content_type not in ("application/atom+xml", "application/rss+xml", "application/xml"):
1.9 raise FeedContentTypeError
1.10
1.11 try:
1.12 @@ -109,12 +109,13 @@
1.13
1.14 feed_type = None
1.15 update = None
1.16 + in_source = False
1.17
1.18 events = xml.dom.pulldom.parse(feed)
1.19
1.20 for event, value in events:
1.21
1.22 - if event == xml.dom.pulldom.START_ELEMENT:
1.23 + if not in_source and event == xml.dom.pulldom.START_ELEMENT:
1.24 tagname = value.localName
1.25
1.26 # Detect the feed type and items.
1.27 @@ -132,6 +133,13 @@
1.28
1.29 update = Update()
1.30
1.31 + # Detect source declarations.
1.32 +
1.33 + elif feed_type == "atom" and tagname == "source":
1.34 + in_source = True
1.35 +
1.36 + # Handle item elements.
1.37 +
1.38 elif tagname == "title":
1.39 events.expandNode(value)
1.40 if update:
1.41 @@ -149,8 +157,11 @@
1.42 elif feed_type == "atom" and tagname == "content":
1.43 events.expandNode(value)
1.44 if update:
1.45 - update.content = text(value)
1.46 update.content_type = value.getAttribute("type")
1.47 + if update.content_type in ("xhtml", "application/xhtml+xml", "application/xml"):
1.48 + update.content = value.toxml()
1.49 + else:
1.50 + update.content = text(value)
1.51
1.52 elif feed_type == "atom" and tagname == "updated" or \
1.53 feed_type == "rss" and tagname == "pubDate":
1.54 @@ -173,6 +184,9 @@
1.55
1.56 update = None
1.57
1.58 + elif feed_type == "atom" and tagname == "source":
1.59 + in_source = False
1.60 +
1.61 finally:
1.62 feed.close()
1.63
1.64 @@ -244,13 +258,18 @@
1.65 for update in updates:
1.66
1.67 # Emit content where appropriate.
1.68 - # NOTE: HTML should be sanitised.
1.69 + # NOTE: HTML and XHTML should be sanitised.
1.70
1.71 if show_content:
1.72 append(fmt.div(on=1, css_class="moinshare-update"))
1.73 append(fmt.div(on=1, css_class="moinshare-content"))
1.74 - if update.content and update.content_type == "html":
1.75 - append(fmt.rawHTML(unescape(update.content)))
1.76 + if update.content:
1.77 + if update.content_type in ("html", "text/html"):
1.78 + append(fmt.rawHTML(unescape(update.content)))
1.79 + elif update.content_type in ("xhtml", "application/xhtml+xml"):
1.80 + append(fmt.rawHTML(update.content))
1.81 + elif update.content_type in ("text", "text/plain"):
1.82 + append(fmt.text(update.content))
1.83 append(fmt.div(on=0))
1.84 append(fmt.div(on=1, css_class="moinshare-date"))
1.85 append(fmt.text(str(update.updated)))