Mercurial > libervia-backend
changeset 842:429c6a0ef73d
frontends (tools): addURLToImage makes an image clickable
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 13 Feb 2014 15:35:21 +0100 |
parents | 831f208b4ea3 |
children | efd92a645220 |
files | frontends/src/tools/strings.py |
diffstat | 1 files changed, 9 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 '<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)