From c157b36e8653b3b2eb91d15cbab0e4f3ddd27ec4 Mon Sep 17 00:00:00 2001 From: at-sign <47769987+at-sign@users.noreply.github.com> Date: Fri, 27 Mar 2026 08:22:29 -0500 Subject: [PATCH] fix rich text links --- slackviewer/message.py | 45 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/slackviewer/message.py b/slackviewer/message.py index 79b01b9..b441394 100644 --- a/slackviewer/message.py +++ b/slackviewer/message.py @@ -100,32 +100,27 @@ def msg(self): text = self._message.get("text", "") if not text or text.strip() == "": text = "[ MESSAGE TEXT EMPTY ]" - return self._formatter.render_text(text) - def _generate_blocks_text(self, blocks): """Build a message together from various message["blocks"]""" text = "" for block in blocks: - if block["type"] in ["rich_text", "rich_text_quote"]: + if block["type"] == "image": + text += self._format_block_type(block, block["type"]) + elif block["type"] in ["rich_text", "rich_text_quote"]: for element in block["elements"]: text += self._format_rich_text_element(element) - elif "fields" in block: for field in block["fields"]: text += self._format_block_type(field, block["type"]) - elif "elements" in block: for element in block["elements"]: text += self._format_block_type(element, block["type"]) - elif "type" in block and block["type"] == "divider": text += "---\n" - else: logging.warning(f"Unknown block type: {block}") - return text def _format_rich_text_element(self, element): @@ -153,9 +148,12 @@ def _format_rich_text_element(self, element): return text elif element["type"] == "link": - text = element.get('text', element['url']).replace("_", "_") - return f"{text}" + text = element.get('text', "") + if not text: + text = element['url'].replace("\\/", "/") + text = text.replace("_", "_") + return f"{text}" elif element["type"] == "user": user = self._formatter.find_user(self.user_message(element['user_id'])) @@ -204,9 +202,6 @@ def _format_rich_text_element(self, element): logging.warning(f"Unsupported rich text element type '{element['type']}' for {element}") return "" - - - def _format_block_type(self, text_obj, b_type): """Format the text based on the block type""" if b_type == "image": @@ -260,30 +255,6 @@ def _format_block_type(self, text_obj, b_type): return f"unsupported_block({b_type}: {text_obj}\n\n)" - - def _generate_blocks_text(self, blocks): - """Build a message together from various message["blocks"]""" - text = "" - for block in blocks: - if block["type"] == "image": - text += self._format_block_type(block, block["type"]) - elif block["type"] in ["rich_text", "rich_text_quote"]: - for element in block["elements"]: - text += self._format_rich_text_element(element) - elif "fields" in block: - for field in block["fields"]: - text += self._format_block_type(field, block["type"]) - elif "elements" in block: - for element in block["elements"]: - text += self._format_block_type(element, block["type"]) - elif "type" in block and block["type"] == "divider": - text += "---\n" - else: - logging.warning(f"Unknown block type: {block}") - return text - - - def user_message(self, user_id): return {"user": user_id}