From 5f59378f8624a85933d8c2ec2258393bfffa5fd6 Mon Sep 17 00:00:00 2001 From: souliane Date: Thu, 13 Feb 2014 15:35:21 +0100 Subject: [PATCH] frontends (tools): addURLToImage makes an image clickable --- frontends/src/tools/strings.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frontends/src/tools/strings.py b/frontends/src/tools/strings.py index 6a1921a5..a244026a 100644 --- a/frontends/src/tools/strings.py +++ b/frontends/src/tools/strings.py @@ -54,3 +54,12 @@ def addURLToText(string): 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 addURLToImage(string): + """Check a XHTML text for what looks like an imageURL and make it clickable""" + def repl(match): + url = match.group(1) + return '%s' % (url, match.group(0)) + pattern = r"""]* src="([^"]+)"[^>]*>""" + return re.sub(pattern, repl, string)