Skip to content

Commit 4e11ce1

Browse files
committed
Also process links starting with www
1 parent 5410cc6 commit 4e11ce1

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

yaml_to_html.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66

77
import re
88

9-
URL_RE = re.compile(r'(https?://[^\s,;]+)')
9+
URL_RE = re.compile(r'\b((?:https?://|www\.)[^\s<>"\']+)', re.IGNORECASE)
10+
1011

1112
def linkify_cell(value):
1213
if not isinstance(value, str):
1314
return value
14-
return URL_RE.sub(r'<a href="\1">\1</a>', value)
15+
16+
def repl(m):
17+
url = m.group(1)
18+
href = url if url.lower().startswith(("http://", "https://")) else f"https://{url}"
19+
return f'<a href="{href}">{url}</a>'
20+
21+
return URL_RE.sub(repl, value)
1522

1623
yaml_file = "problems.yaml"
1724

0 commit comments

Comments
 (0)