Skip to content

Commit

Permalink
Merge pull request #14 from RyanLua/hyperlinked-mentions
Browse files Browse the repository at this point in the history
Add hyperlinks for mentions
  • Loading branch information
RyanLua authored Aug 20, 2024
2 parents 26983d6 + 3ce0e1d commit 074c933
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/instawebhooks/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,18 @@ async def create_embed(post: Post):
post_image_file = File(io.BytesIO(post_image_bytes), "post_image.webp")
profile_pic_file = File(io.BytesIO(profile_pic_bytes), "profile_pic.webp")

# Replace hashtags with clickable links
if post.caption is None:
post_caption = ""
else:
post_caption = re.sub(
r"#([a-zA-Z0-9]+\b)",
r"[#\1](https://www.instagram.com/explore/tags/\1)",
post.caption,
)
# Format the post caption with clickable links for mentions and hashtags
post_caption = post.caption or ""
post_caption = re.sub(
r"#([a-zA-Z0-9]+\b)",
r"[#\1](https://www.instagram.com/explore/tags/\1)",
post_caption,
)
post_caption = re.sub(
r"@([a-zA-Z0-9_]+\b)",
r"[@\1](https://www.instagram.com/\1)",
post_caption,
)

embed = Embed(
color=13500529,
Expand Down

0 comments on commit 074c933

Please sign in to comment.