diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2017-09-26 17:49:19 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2017-10-01 20:14:53 +0200 |
commit | 7888e6056d812490a58d03843d6f722dc1c4a19c (patch) | |
tree | ca852925a72e5524e5d6e94362cdb995673bb076 | |
parent | 2f43d1b6466c74e8774e2833214f847eb559f15a (diff) | |
download | wee-slack-7888e6056d812490a58d03843d6f722dc1c4a19c.tar.gz |
feat: Remove Slacks auto prefixing of url protocols
When you write multiple words separated by dots, or email adresses,
Slack will turn those into links. Wee-slack will display this as
`text (url)`, where url is just the text with http:// or mailto:
prefixed. This makes the text hard to read, and might not even make
sense (e.g. when writing server names or user@hostname).
When you receive such an url, the alt text of the url will be the
original text. This means that we can check if the url is just the alt
text with a protocol prefixed. If it is, we should just print the alt
text and ignore the url.
I guess some people may want the urls, so they are able to click the
links. And since it removes information coming from slack, I made it
into an option instead of making it the default.
-rw-r--r-- | wee_slack.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/wee_slack.py b/wee_slack.py index 90b56ac..e340093 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2587,7 +2587,12 @@ def unfurl_ref(ref, ignore_alt_text=False): display_text = ref.split('|')[1] else: url, desc = ref.split('|', 1) - display_text = "{} ({})".format(url, desc) + if (config.unfurl_prevent_auto_linking and + match_url = r"^\w+:(//)?{}$".format(re.escape(desc)) + re.match(match_url, url)): + display_text = desc + else: + display_text = "{} ({})".format(url, desc) else: display_text = resolve_ref(ref) return display_text @@ -3395,6 +3400,13 @@ 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', + 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.'), 'unhide_buffers_with_activity': Setting( default='false', desc='When activity occurs on a buffer, unhide it even if it was' |