Skip to content

Commit

Permalink
Use regex for urls
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Sep 8, 2023
1 parent 916a223 commit e9645a0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import os
import json
import re
import shutil
import uuid

Expand Down Expand Up @@ -164,14 +165,12 @@ def rm_crossline(self, text: str) -> str:
@classmethod
def find_url(self, text: str) -> str:
"""Convert urls to markup. Make sure to escape text before calling."""
arr: list = text.split(" ")
new_str = []
for i in arr:
if i.startswith("http://") or i.startswith("https://"):
new_str.append(f'<a href="{i}">{i}</a>')
else:
new_str.append(i)
return " ".join(new_str)

string = text
urls = re.findall(r"(https?://\S+)", string)
for url in urls:
string = string.replace(url, f'<a href="{url}">{url}</a>')
return string


class TaskUtils:
Expand Down

0 comments on commit e9645a0

Please sign in to comment.