aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2017-10-01 21:00:36 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2017-10-01 21:11:47 +0200
commitc6087453d64d9158395b7227d7545bb26f36411c (patch)
tree49dccb9ba7040d13f20bcc8b7ff12ec3643b41eb /wee_slack.py
parent7888e6056d812490a58d03843d6f722dc1c4a19c (diff)
downloadwee-slack-c6087453d64d9158395b7227d7545bb26f36411c.tar.gz
feat: Make it possible to only display url when text matches
This changes the feature from the previous commit so it's also possible to only display the url when the text and the url (without the protocol) in a link is equal.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/wee_slack.py b/wee_slack.py
index e340093..23bb115 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2587,10 +2587,12 @@ def unfurl_ref(ref, ignore_alt_text=False):
display_text = ref.split('|')[1]
else:
url, desc = ref.split('|', 1)
- if (config.unfurl_prevent_auto_linking and
- match_url = r"^\w+:(//)?{}$".format(re.escape(desc))
- re.match(match_url, url)):
+ match_url = r"^\w+:(//)?{}$".format(re.escape(desc))
+ url_matches_desc = re.match(match_url, url)
+ if url_matches_desc and config.unfurl_auto_link_display == "text":
display_text = desc
+ elif url_matches_desc and config.unfurl_auto_link_display == "url":
+ display_text = url
else:
display_text = "{} ({})".format(url, desc)
else:
@@ -3400,13 +3402,15 @@ class PluginConfig(object):
desc='When displaying ("unfurling") links to channels/users/etc,'
' ignore the "alt text" present in the message and instead use the'
' canonical name of the thing being linked to.'),
- 'unfurl_prevent_auto_linking': Setting(
- default='false',
+ 'unfurl_auto_link_display': Setting(
+ default='both',
desc='When displaying ("unfurling") links to channels/users/etc,'
- ' only show the "alt text" if that is the same as the url without'
- ' the protocol. This is useful because Slack inserts http:// in'
- ' front of words containg dots and mailto: in front of email'
- ' addresses, so this will remove it.'),
+ ' determine what is displayed when the text matches the url'
+ ' without the protocol. This happens when Slack automatically'
+ ' creates links, e.g. from words separated by dots or email'
+ ' addresses. Set it to "text" to only display the text written by'
+ ' the user, "url" to only display the url or "both" (the default)'
+ ' to display both.'),
'unhide_buffers_with_activity': Setting(
default='false',
desc='When activity occurs on a buffer, unhide it even if it was'
@@ -3472,6 +3476,7 @@ class PluginConfig(object):
get_render_italic_as = get_string
get_slack_timeout = get_int
get_thread_suffix_color = get_string
+ get_unfurl_auto_link_display = get_string
def get_distracting_channels(self, key):
return [x.strip() for x in w.config_get_plugin(key).split(',')]