# HG changeset patch # User souliane # Date 1392302121 -3600 # Node ID 429c6a0ef73debb2cea306a97f7b4eef6a7a862f # Parent 831f208b4ea33058a7a5114ba71697e473001264 frontends (tools): addURLToImage makes an image clickable diff -r 831f208b4ea3 -r 429c6a0ef73d frontends/src/tools/strings.py --- a/frontends/src/tools/strings.py Thu Feb 13 12:29:14 2014 +0100 +++ b/frontends/src/tools/strings.py Thu Feb 13 15:35:21 2014 +0100 @@ -54,3 +54,12 @@ 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)