frontends (tools): addURLToImage makes an image clickable

This commit is contained in:
souliane 2014-02-13 15:35:21 +01:00
commit 5f59378f86

View file

@ -54,3 +54,12 @@ def addURLToText(string):
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 addURLToImage(string):
"""Check a XHTML text for what looks like an imageURL and make it clickable"""
def repl(match):
url = match.group(1)
return '<a href="%s" target="_blank">%s</a>' % (url, match.group(0))
pattern = r"""<img[^>]* src="([^"]+)"[^>]*>"""
return re.sub(pattern, repl, string)