Include 'www.' in twitter/youtube link replacement

This commit is contained in:
Zed 2019-08-15 19:19:21 +02:00
parent 9fc512d88d
commit 6c365b8fba

View file

@ -11,8 +11,8 @@ const
usernameRegex = re"(^|[^A-z0-9_?])@([A-z0-9_]+)" usernameRegex = re"(^|[^A-z0-9_?])@([A-z0-9_]+)"
picRegex = re"pic.twitter.com/[^ ]+" picRegex = re"pic.twitter.com/[^ ]+"
ellipsisRegex = re" ?…" ellipsisRegex = re" ?…"
ytRegex = re"youtu(be.com|.be)" ytRegex = re"(www.)?youtu(be.com|.be)"
twRegex = re"twitter.com" twRegex = re"(www.)?twitter.com"
nbsp = $Rune(0x000A0) nbsp = $Rune(0x000A0)
proc stripText*(text: string): string = proc stripText*(text: string): string =
@ -65,9 +65,9 @@ proc linkifyText*(text: string; prefs: Prefs): string =
proc replaceUrl*(url: string; prefs: Prefs): string = proc replaceUrl*(url: string; prefs: Prefs): string =
result = url result = url
if prefs.replaceYouTube.len > 0: if prefs.replaceYouTube.len > 0:
result = url.replace(ytRegex, prefs.replaceYouTube) result = result.replace(ytRegex, prefs.replaceYouTube)
if prefs.replaceTwitter.len > 0: if prefs.replaceTwitter.len > 0:
result = url.replace(twRegex, prefs.replaceTwitter) result = result.replace(twRegex, prefs.replaceTwitter)
proc stripTwitterUrls*(text: string): string = proc stripTwitterUrls*(text: string): string =
result = text result = text