Skip to content

Fix rich text naked urls - #238

Open
at-sign wants to merge 1 commit into
hfaran:masterfrom
at-sign:master
Open

Fix rich text naked urls#238
at-sign wants to merge 1 commit into
hfaran:masterfrom
at-sign:master

Conversation

@at-sign

@at-sign at-sign commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

This corrects an issue where the way blocks were used to build messages did not display links unless they were hyperlinked text. If they were naked urls, there was no visible link text.

The naked url will now show.

Comment thread slackviewer/message.py
return f"<a href='{element['url']}'>{text}</a>"
text = element.get('text', "")
if not text:
text = element['url'].replace("\\/", "/")

@hfaran hfaran Jun 1, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding the following explanation as a comment above this: Slack's block kit JSON sometimes encodes forward slashes as /(a valid JSON escape). Python'sjson module may leave these as literal backslash+slash depending on the serialiser, so this replacement normalises them before using the URL as display text.

Comment thread slackviewer/message.py
text = element['url'].replace("\\/", "/")

text = text.replace("_", "&#95;")
return f"<a href='{element['url']}'>{text}</a>"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

element['url'] will raise KeyError if the field is absent. Consider element.get('url', '') here (and in the href) for safety.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants