Enhance Slack message formatting with new regex rules

Added regex substitutions for strikethrough, URL formatting, and image URLs in Slack message conversion.
This commit is contained in:
Aleksander W. Oleszkiewicz (Alek) 2026-02-16 09:49:44 +01:00 committed by GitHub
parent 7e2d801ffc
commit 90be900448
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -223,9 +223,21 @@ class SlackChannel(BaseChannel):
# Step 3.a: ***text*** -> *_text_*
converted_text = re.sub(
r"(?m)(^|[^\*])\*\*\*([^\*].+?[^\*])\*\*\*([^\*]|$)", r"\1*_\2_*\3", converted_text)
# Step 3.b - ___text___ to *_text_*
# Step 3.b - ___text___ -> *_text_*
converted_text = re.sub(
r"(?m)(^|[^_])___([^_].+?[^_])___([^_]|$)", r"\1*_\2_*\3", converted_text)
# Convert strikethrough
# Step 4: ~~text~~ -> ~text~
converted_text = re.sub(
r"(?m)(^|[^~])~~([^~].+?[^~])~~([^~]|$)", r"\1~\2~\3", converted_text)
# Convert URL formatting
# Step 6: [text](URL) -> <URL|text>
converted_text = re.sub(
r"(^|[^!])\[(.+?)\]\((http.+?)\)", r"<\2|\1>", converted_text)
# Convert image URL
# Step 6: ![alt text](URL "title") -> <URL>
converted_text = re.sub(
r"[!]\[.+?\]\((http.+?)(?: \".*?\")?\)", r"<\2>", converted_text)
return converted_text
def escape_mrkdwn(text: str) -> str:
return (text.replace('&', '&amp;')