diff options
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/wee_slack.py b/wee_slack.py index 23bb115..6b7a5d8 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2498,9 +2498,9 @@ def render(message_json, team, channel, force=False): else: text = "" - text = unfurl_refs(text, ignore_alt_text=config.unfurl_ignore_alt_text) + text = unfurl_refs(text) - text += unfurl_refs(unwrap_attachments(message_json, text), ignore_alt_text=config.unfurl_ignore_alt_text) + text += unfurl_refs(unwrap_attachments(message_json, text)) text = text.lstrip() text = unhtmlescape(text.replace("\t", " ")) @@ -2557,7 +2557,7 @@ def linkify_text(message, team, channel): return " ".join(message) -def unfurl_refs(text, ignore_alt_text=False): +def unfurl_refs(text, ignore_alt_text=None, auto_link_display=None): """ input : <@U096Q7CQM|someuser> has joined the channel ouput : someuser has joined the channel @@ -2567,14 +2567,21 @@ def unfurl_refs(text, ignore_alt_text=False): # - <#C2147483705|#otherchannel> # - <@U2147483697|@othernick> # Test patterns lives in ./_pytest/test_unfurl.py + + if ignore_alt_text is None: + ignore_alt_text = config.unfurl_ignore_alt_text + if auto_link_display is None: + auto_link_display = config.unfurl_auto_link_display + matches = re.findall(r"(<[@#]?(?:[^>]*)>)", text) for m in matches: # Replace them with human readable strings - text = text.replace(m, unfurl_ref(m[1:-1], ignore_alt_text)) + text = text.replace( + m, unfurl_ref(m[1:-1], ignore_alt_text, auto_link_display)) return text -def unfurl_ref(ref, ignore_alt_text=False): +def unfurl_ref(ref, ignore_alt_text, auto_link_display): id = ref.split('|')[0] display_text = ref if ref.find('|') > -1: @@ -2589,9 +2596,9 @@ def unfurl_ref(ref, ignore_alt_text=False): url, desc = ref.split('|', 1) 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": + if url_matches_desc and auto_link_display == "text": display_text = desc - elif url_matches_desc and config.unfurl_auto_link_display == "url": + elif url_matches_desc and auto_link_display == "url": display_text = url else: display_text = "{} ({})".format(url, desc) |