Mercurial > libervia-web
changeset 246:d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 09 Nov 2013 10:24:03 +0100 (2013-11-09) |
parents | 43881c3dda9d |
children | fe83837d3491 |
files | browser_side/panels.py browser_side/tools.py |
diffstat | 2 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/browser_side/panels.py Sat Nov 09 10:23:33 2013 +0100 +++ b/browser_side/panels.py Sat Nov 09 10:24:03 2013 +0100 @@ -43,7 +43,7 @@ from radiocol import RadioColPanel from menu import Menu from jid import JID -from tools import html_sanitize, addURLToText +from tools import html_sanitize, addURLToText, inlineRoot from datetime import datetime from time import time import dialog @@ -619,7 +619,7 @@ {"timestamp": _date.strftime("%H:%M"), "nick": "[%s]" % html_sanitize(nick), "msg_class": ' '.join(_msg_class), - "msg": addURLToText(html_sanitize(msg)) if not xhtml else xhtml} #FIXME: images and external links must be removed according to preferences + "msg": addURLToText(html_sanitize(msg)) if not xhtml else inlineRoot(xhtml)} #FIXME: images and external links must be removed according to preferences ) self.setStyleName('chatText')
--- a/browser_side/tools.py Sat Nov 09 10:23:33 2013 +0100 +++ b/browser_side/tools.py Sat Nov 09 10:24:03 2013 +0100 @@ -21,12 +21,21 @@ from pyjamas.ui.DragWidget import DragWidget import re +from nativedom import NativeDOM +from sat.tools.frontends import xml + +dom = NativeDOM() def html_sanitize(html): """Naive sanitization of HTML""" return html.replace('<','<').replace('>','>') +def inlineRoot(xhtml): + """ make root element inline """ + doc = dom.parseString(xhtml) + return xml.inlineRoot(doc) + def addURLToText(string): """Check a text for what looks like an URL and make it clickable. Regexp from http://daringfireball.net/2010/07/improved_regex_for_matching_urls"""