Fix rich text naked urls - #238
Open
at-sign wants to merge 1 commit into
Open
Conversation
hfaran
reviewed
Jun 1, 2026
| return f"<a href='{element['url']}'>{text}</a>" | ||
| text = element.get('text', "") | ||
| if not text: | ||
| text = element['url'].replace("\\/", "/") |
Owner
There was a problem hiding this comment.
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.
| text = element['url'].replace("\\/", "/") | ||
|
|
||
| text = text.replace("_", "_") | ||
| return f"<a href='{element['url']}'>{text}</a>" |
Owner
There was a problem hiding this comment.
element['url'] will raise KeyError if the field is absent. Consider element.get('url', '') here (and in the href) for safety.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.