Mercurial > libervia-web
changeset 306:52b1afd7ac3f
server_side: display rich text in blogs (addURLToText is now in sat_frontends/tools/strings)
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 18 Dec 2013 15:39:13 +0100 |
parents | d002cd631271 |
children | 44b46db7dfef |
files | browser_side/panels.py browser_side/tools.py server_css/blog.css server_side/blog.py |
diffstat | 4 files changed, 9 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 '<a href="%s" target="_blank" class="url">%s</a>' % (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
--- 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); +}
--- 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 <http://www.gnu.org/licenses/>. """ +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("""<div class='mblog_entry'><span class='mblog_timestamp'>%(date)s</span> <span class='mblog_content'>%(content)s</span></div>""" % { 'date': _datetime, - 'content': sanitizeHtml(entry['content']).encode('utf-8')}) + 'content': body}) request.write('</body></html>') request.finish()