1.1 --- a/MoinShare.py Tue May 14 17:16:56 2013 +0200
1.2 +++ b/MoinShare.py Tue May 14 23:14:39 2013 +0200
1.3 @@ -180,7 +180,7 @@
1.4 fmt.setPage(page)
1.5 update.content = formatText(body, request, fmt, parser_cls)
1.6
1.7 - update.content_type = "html"
1.8 + update.content_type = "text/html"
1.9
1.10 update.link = page.url(request)
1.11 update.updated = updated
2.1 --- a/macros/SharedContent.py Tue May 14 17:16:56 2013 +0200
2.2 +++ b/macros/SharedContent.py Tue May 14 23:14:39 2013 +0200
2.3 @@ -9,7 +9,7 @@
2.4 from DateSupport import getDateTimeFromISO8601, DateTime
2.5 from MoinMoin.Page import Page
2.6 from MoinRemoteSupport import *
2.7 -from MoinSupport import parseMacroArguments
2.8 +from MoinSupport import parseMacroArguments, getParsersForContentType, formatText
2.9 from MoinShare import getUpdateSources, getUpdatesFromPage, Update
2.10 from email.utils import parsedate
2.11 import xml.dom.pulldom
2.12 @@ -33,6 +33,12 @@
2.13 nodes.append(node.nodeValue)
2.14 return "".join(nodes)
2.15
2.16 +def children(element):
2.17 + nodes = []
2.18 + for node in element.childNodes:
2.19 + nodes.append(node.toxml())
2.20 + return "".join(nodes)
2.21 +
2.22 def unescape(text):
2.23 return text.replace("<", "<").replace(">", ">").replace("&", "&")
2.24
2.25 @@ -152,12 +158,21 @@
2.26 if update and (need_content(show_content, tagname) or tagname == "summary" and not update.content):
2.27 if feed_type == "atom":
2.28 update.content_type = value.getAttribute("type") or "text"
2.29 +
2.30 + # Normalise the content types and extract the
2.31 + # content.
2.32 +
2.33 if update.content_type in ("xhtml", "application/xhtml+xml", "application/xml"):
2.34 - update.content = value.toxml()
2.35 + update.content = children(value)
2.36 + update.content_type = "application/xhtml+xml"
2.37 + elif update.content_type in ("html", "text/html"):
2.38 + update.content = text(value)
2.39 + update.content_type = "text/html"
2.40 else:
2.41 update.content = text(value)
2.42 + update.content_type = "text/plain"
2.43 else:
2.44 - update.content_type = "html"
2.45 + update.content_type = "text/html"
2.46 update.content = text(value)
2.47
2.48 elif feed_type == "atom" and tagname == "updated" or \
2.49 @@ -296,18 +311,22 @@
2.50 for update in updates:
2.51
2.52 # Emit content where appropriate.
2.53 - # NOTE: HTML and XHTML should be sanitised.
2.54 + # NOTE: Some control over the HTML and XHTML should be exercised.
2.55
2.56 if show_content:
2.57 append(fmt.div(on=1, css_class="moinshare-update"))
2.58 append(fmt.div(on=1, css_class="moinshare-content"))
2.59 +
2.60 if update.content:
2.61 - if update.content_type in ("html", "text/html"):
2.62 - append(fmt.rawHTML(unescape(update.content)))
2.63 - elif update.content_type in ("xhtml", "application/xhtml+xml"):
2.64 - append(fmt.rawHTML(update.content))
2.65 - elif update.content_type in ("text", "text/plain"):
2.66 - append(fmt.text(update.content))
2.67 + parsers = getParsersForContentType(request.cfg, update.content_type)
2.68 +
2.69 + if parsers:
2.70 + for parser_cls in parsers:
2.71 + append(formatText(update.content, request, fmt, parser_cls=parser_cls))
2.72 + break
2.73 + else:
2.74 + append(fmt.text(_("Update cannot be shown for content of type %s.") % update.content_type))
2.75 +
2.76 append(fmt.div(on=0))
2.77 append(fmt.div(on=1, css_class="moinshare-date"))
2.78 append(fmt.text(str(update.updated)))