aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-09-22 16:48:12 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2023-09-22 16:48:12 +0200
commit870a704e7e182d4bba2ed18f20493af1f22e9c5c (patch)
tree7dfc62bd05eda21a9296f0ebc57a05213b479e45 /wee_slack.py
parent2050552f6aed3525e2c32e70b40c7ba64c6eb103 (diff)
downloadwee-slack-870a704e7e182d4bba2ed18f20493af1f22e9c5c.tar.gz
Fix links/refs not being processed in normal blocks
In commit 6478c14 the block rendering was changed to escape `<` and `>`. However, this caused links and refs in normal (not rich_text) blocks to be shown as refs instead of rendered correctly. The correct behavior is to not process refs in rich_text blocks, but do it in normal blocks.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 56944f8..5567f09 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -4614,7 +4614,7 @@ def unfurl_blocks(blocks):
lines = [
"> {}".format(line)
for e in element["elements"]
- for line in unfurl_block_element(e).split("\n")
+ for line in unfurl_block_rich_text_element(e).split("\n")
]
block_text.extend(lines)
elif element["type"] == "rich_text_preformatted":
@@ -4745,7 +4745,7 @@ def unfurl_rich_text_section(block):
texts.extend(reversed(colors_remove))
texts.extend(colors_apply)
texts.extend(characters_apply)
- texts.append(unfurl_block_element(element))
+ texts.append(unfurl_block_rich_text_element(element))
prev_element = element
text = "".join(texts)
@@ -4756,16 +4756,9 @@ def unfurl_rich_text_section(block):
return text
-def unfurl_block_element(element):
- if element["type"] == "mrkdwn":
- return htmlescape(render_formatting(element["text"]))
- elif element["type"] in ["text", "plain_text"]:
+def unfurl_block_rich_text_element(element):
+ if element["type"] == "text":
return htmlescape(element["text"])
- elif element["type"] == "image":
- if element.get("alt_text"):
- return "{} ({})".format(element["image_url"], element["alt_text"])
- else:
- return element["image_url"]
elif element["type"] == "link":
text = element.get("text")
if text and text != element["url"]:
@@ -4786,6 +4779,24 @@ def unfurl_block_element(element):
elif element["type"] == "channel":
return resolve_ref("#{}".format(element["channel_id"]))
else:
+ dbg("Unsupported rich text element: '{}'".format(json.dumps(element)), level=4)
+ return colorize_string(
+ config.color_deleted,
+ '<<Unsupported rich text element type "{}">>'.format(element["type"]),
+ )
+
+
+def unfurl_block_element(element):
+ if element["type"] == "mrkdwn":
+ return render_formatting(element["text"])
+ elif element["type"] == "plain_text":
+ return element["text"]
+ elif element["type"] == "image":
+ if element.get("alt_text"):
+ return "{} ({})".format(element["image_url"], element["alt_text"])
+ else:
+ return element["image_url"]
+ else:
dbg("Unsupported block element: '{}'".format(json.dumps(element)), level=4)
return colorize_string(
config.color_deleted,