Mercurial > libervia-backend
comparison libervia/frontends/tools/strings.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 26b7ed2817da |
children |
comparison
equal
deleted
inserted
replaced
4269:64a85ce8be70 | 4270:0d7bb4df2343 |
---|---|
55 """Check a text for what looks like an URL and make it clickable. | 55 """Check a text for what looks like an URL and make it clickable. |
56 | 56 |
57 @param string (unicode): text to process | 57 @param string (unicode): text to process |
58 @param new_target (bool): if True, make the link open in a new window | 58 @param new_target (bool): if True, make the link open in a new window |
59 """ | 59 """ |
60 | |
60 # XXX: report any change to libervia.browser.strings.add_url_to_text | 61 # XXX: report any change to libervia.browser.strings.add_url_to_text |
61 def repl(match): | 62 def repl(match): |
62 url = match.group(0) | 63 url = match.group(0) |
63 if not re.match(r"""[a-z]{3,}://|mailto:|xmpp:""", url): | 64 if not re.match(r"""[a-z]{3,}://|mailto:|xmpp:""", url): |
64 url = "http://" + url | 65 url = "http://" + url |
71 def add_url_to_image(string): | 72 def add_url_to_image(string): |
72 """Check a XHTML text for what looks like an imageURL and make it clickable. | 73 """Check a XHTML text for what looks like an imageURL and make it clickable. |
73 | 74 |
74 @param string (unicode): text to process | 75 @param string (unicode): text to process |
75 """ | 76 """ |
77 | |
76 # XXX: report any change to libervia.browser.strings.add_url_to_image | 78 # XXX: report any change to libervia.browser.strings.add_url_to_image |
77 def repl(match): | 79 def repl(match): |
78 url = match.group(1) | 80 url = match.group(1) |
79 return '<a href="%s" target="_blank">%s</a>' % (url, match.group(0)) | 81 return '<a href="%s" target="_blank">%s</a>' % (url, match.group(0)) |
80 | 82 |