frontends (tools): addURLToImage makes an image clickable
This commit is contained in:
parent
d5fb045f5b
commit
5f59378f86
1 changed files with 9 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue