diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-08-24 21:41:47 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2023-08-24 21:43:30 +0200 |
commit | c3d200075dc2a4c019ee5547129de45e371d050d (patch) | |
tree | 7b5238b0d365447ff73a247ffbd9f9d9c0ac5bc4 | |
parent | 15fa724a00c415354c2f0ffa5e1c91cf3336d503 (diff) | |
download | wee-slack-c3d200075dc2a4c019ee5547129de45e371d050d.tar.gz |
Fix regresion with option unfurl_auto_link_display
This option wasn't accounted for when the message rendering was changed
to using blocks in commit 74da303.
-rw-r--r-- | wee_slack.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/wee_slack.py b/wee_slack.py index a699c42..f439d58 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -4772,11 +4772,12 @@ def unfurl_block_element(element): else: return element["image_url"] elif element["type"] == "link": - if element.get("text"): + text = element.get("text") + if text and text != element["url"]: if element.get("style", {}).get("code"): - return element["text"] + return text else: - return "{} ({})".format(element["url"], element["text"]) + return unfurl_link(element["url"], text) else: return element["url"] elif element["type"] == "emoji": @@ -4797,6 +4798,17 @@ def unfurl_block_element(element): ) +def unfurl_link(url, text): + match_url = r"^\w+:(//)?{}$".format(re.escape(text)) + url_matches_desc = re.match(match_url, url) + if url_matches_desc and config.unfurl_auto_link_display == "text": + return text + elif url_matches_desc and config.unfurl_auto_link_display == "url": + return url + else: + return "{} ({})".format(url, text) + + def unfurl_refs(text): """ input : <@U096Q7CQM|someuser> has joined the channel @@ -4827,14 +4839,7 @@ def unfurl_refs(text): elif ref.startswith("!date"): return fallback else: - match_url = r"^\w+:(//)?{}$".format(re.escape(fallback)) - url_matches_desc = re.match(match_url, ref) - if url_matches_desc and config.unfurl_auto_link_display == "text": - return fallback - elif url_matches_desc and config.unfurl_auto_link_display == "url": - return ref - else: - return "{} ({})".format(ref, fallback) + return unfurl_link(ref, fallback) return ref return re.sub(r"<([^|>]*)(?:\|([^>]*))?>", unfurl_ref, text) |