# HG changeset patch # User souliane # Date 1387377553 -3600 # Node ID 52b1afd7ac3fb68d7df24d0040654ea99f9cc04f # Parent d002cd6312714f352d00d5ee6be15876c38f1edd server_side: display rich text in blogs (addURLToText is now in sat_frontends/tools/strings) diff -r d002cd631271 -r 52b1afd7ac3f browser_side/panels.py --- a/browser_side/panels.py Wed Dec 18 13:59:25 2013 +0100 +++ b/browser_side/panels.py Wed Dec 18 15:39:13 2013 +0100 @@ -44,7 +44,8 @@ from radiocol import RadioColPanel from menu import Menu from jid import JID -from tools import html_sanitize, addURLToText, inlineRoot, setPresenceStyle +from tools import html_sanitize, inlineRoot, setPresenceStyle +from sat_frontends.tools.strings import addURLToText from datetime import datetime from time import time import dialog diff -r d002cd631271 -r 52b1afd7ac3f browser_side/tools.py --- a/browser_side/tools.py Wed Dec 18 13:59:25 2013 +0100 +++ b/browser_side/tools.py Wed Dec 18 15:39:13 2013 +0100 @@ -22,7 +22,6 @@ from pyjamas.ui.DragWidget import DragWidget from pyjamas.ui.FileUpload import FileUpload from pyjamas import Window -import re from nativedom import NativeDOM from sat_frontends.tools import xml @@ -40,19 +39,6 @@ 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""" - - def repl(match): - url = match.group(0) - if not re.match(r"""[a-z]{3,}://|mailto:|xmpp:""", url): - url = "http://" + url - return '%s' % (url, match.group(0)) - pattern = r"""(?i)\b((?:[a-z]{3,}://|(www|ftp)\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/|mailto:|xmpp:)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?]))""" - return re.sub(pattern, repl, string) - - def setPresenceStyle(item, state, base_style="contact"): """ @item: any UI element diff -r d002cd631271 -r 52b1afd7ac3f server_css/blog.css --- a/server_css/blog.css Wed Dec 18 13:59:25 2013 +0100 +++ b/server_css/blog.css Wed Dec 18 15:39:13 2013 +0100 @@ -51,3 +51,7 @@ display: block; padding-top: 5px; } + +h1, h2, h3, h4, h5, h6 { + border-bottom: 1px solid rgb(170, 170, 170); +} diff -r d002cd631271 -r 52b1afd7ac3f server_side/blog.py --- a/server_side/blog.py Wed Dec 18 13:59:25 2013 +0100 +++ b/server_side/blog.py Wed Dec 18 15:39:13 2013 +0100 @@ -19,6 +19,7 @@ along with this program. If not, see . """ +from sat_frontends.tools.strings import addURLToText from server_side.html_tools import sanitizeHtml from twisted.internet import reactor, defer from twisted.web import server @@ -88,10 +89,11 @@ for entry in mblog_data: timestamp = float(entry.get('timestamp', 0)) _datetime = datetime.fromtimestamp(timestamp) + body = addURLToText(sanitizeHtml(entry['content'])).encode('utf-8') if 'xhtml' not in entry else entry['xhtml'].encode() request.write("""
%(date)s %(content)s
""" % { 'date': _datetime, - 'content': sanitizeHtml(entry['content']).encode('utf-8')}) + 'content': body}) request.write('') request.finish()