1.1 --- a/macros/SharedContent.py Tue May 14 17:16:56 2013 +0200
1.2 +++ b/macros/SharedContent.py Tue May 14 23:14:39 2013 +0200
1.3 @@ -9,7 +9,7 @@
1.4 from DateSupport import getDateTimeFromISO8601, DateTime
1.5 from MoinMoin.Page import Page
1.6 from MoinRemoteSupport import *
1.7 -from MoinSupport import parseMacroArguments
1.8 +from MoinSupport import parseMacroArguments, getParsersForContentType, formatText
1.9 from MoinShare import getUpdateSources, getUpdatesFromPage, Update
1.10 from email.utils import parsedate
1.11 import xml.dom.pulldom
1.12 @@ -33,6 +33,12 @@
1.13 nodes.append(node.nodeValue)
1.14 return "".join(nodes)
1.15
1.16 +def children(element):
1.17 + nodes = []
1.18 + for node in element.childNodes:
1.19 + nodes.append(node.toxml())
1.20 + return "".join(nodes)
1.21 +
1.22 def unescape(text):
1.23 return text.replace("<", "<").replace(">", ">").replace("&", "&")
1.24
1.25 @@ -152,12 +158,21 @@
1.26 if update and (need_content(show_content, tagname) or tagname == "summary" and not update.content):
1.27 if feed_type == "atom":
1.28 update.content_type = value.getAttribute("type") or "text"
1.29 +
1.30 + # Normalise the content types and extract the
1.31 + # content.
1.32 +
1.33 if update.content_type in ("xhtml", "application/xhtml+xml", "application/xml"):
1.34 - update.content = value.toxml()
1.35 + update.content = children(value)
1.36 + update.content_type = "application/xhtml+xml"
1.37 + elif update.content_type in ("html", "text/html"):
1.38 + update.content = text(value)
1.39 + update.content_type = "text/html"
1.40 else:
1.41 update.content = text(value)
1.42 + update.content_type = "text/plain"
1.43 else:
1.44 - update.content_type = "html"
1.45 + update.content_type = "text/html"
1.46 update.content = text(value)
1.47
1.48 elif feed_type == "atom" and tagname == "updated" or \
1.49 @@ -296,18 +311,22 @@
1.50 for update in updates:
1.51
1.52 # Emit content where appropriate.
1.53 - # NOTE: HTML and XHTML should be sanitised.
1.54 + # NOTE: Some control over the HTML and XHTML should be exercised.
1.55
1.56 if show_content:
1.57 append(fmt.div(on=1, css_class="moinshare-update"))
1.58 append(fmt.div(on=1, css_class="moinshare-content"))
1.59 +
1.60 if update.content:
1.61 - if update.content_type in ("html", "text/html"):
1.62 - append(fmt.rawHTML(unescape(update.content)))
1.63 - elif update.content_type in ("xhtml", "application/xhtml+xml"):
1.64 - append(fmt.rawHTML(update.content))
1.65 - elif update.content_type in ("text", "text/plain"):
1.66 - append(fmt.text(update.content))
1.67 + parsers = getParsersForContentType(request.cfg, update.content_type)
1.68 +
1.69 + if parsers:
1.70 + for parser_cls in parsers:
1.71 + append(formatText(update.content, request, fmt, parser_cls=parser_cls))
1.72 + break
1.73 + else:
1.74 + append(fmt.text(_("Update cannot be shown for content of type %s.") % update.content_type))
1.75 +
1.76 append(fmt.div(on=0))
1.77 append(fmt.div(on=1, css_class="moinshare-date"))
1.78 append(fmt.text(str(update.updated)))