diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-10-25 01:06:08 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2023-10-25 01:06:08 +0200 |
commit | cf244bb2b9571b64bdd9b9e9ec3ac4e74a213190 (patch) | |
tree | 091e0f03a2af068fbf3152595cdef99d8bc570bd | |
parent | 26eb1eb1957aa2a7a1d74a2dabb141958464a091 (diff) | |
download | wee-slack-cf244bb2b9571b64bdd9b9e9ec3ac4e74a213190.tar.gz |
Support color rich text elements
Fixes #912
-rw-r--r-- | _pytest/test_render_blocks.py | 15 | ||||
-rw-r--r-- | wee_slack.py | 4 |
2 files changed, 19 insertions, 0 deletions
diff --git a/_pytest/test_render_blocks.py b/_pytest/test_render_blocks.py index d852fb3..13a20e9 100644 --- a/_pytest/test_render_blocks.py +++ b/_pytest/test_render_blocks.py @@ -353,6 +353,21 @@ import wee_slack "<[color bold]><[color italic]>*_bold and italic combined_*<[color -italic]><[color -bold]>" ], }, + { + "blocks": [ + { + "type": "rich_text", + "block_id": "M23r4", + "elements": [ + { + "type": "rich_text_section", + "elements": [{"type": "color", "value": "#FFAA00"}], + } + ], + } + ], + "rendered": ["#FFAA00 <[color 16755200]>■<[color reset]>"], + }, ], ) def test_render_blocks(case): diff --git a/wee_slack.py b/wee_slack.py index 1709190..88949d9 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -4783,6 +4783,10 @@ def unfurl_block_rich_text_element(element): return element["url"] elif element["type"] == "emoji": return replace_string_with_emoji(":{}:".format(element["name"])) + elif element["type"] == "color": + rgb_int = int(element["value"].lstrip("#"), 16) + weechat_color = w.info_get("color_rgb2term", str(rgb_int)) + return "{} {}".format(element["value"], colorize_string(weechat_color, "■")) elif element["type"] == "user": return resolve_ref("@{}".format(element["user_id"])) elif element["type"] == "usergroup": |