mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-17 13:36:34 +00:00
Fix link regex edgecases
This commit is contained in:
parent
aae0e51154
commit
b31cc7bc25
1 changed files with 4 additions and 5 deletions
|
@ -6,9 +6,9 @@ import ./types, ./utils
|
|||
from unicode import Rune, `$`
|
||||
|
||||
const
|
||||
urlRegex = re"((https?|ftp)://(-\.)?([^\s/?\.#]+\.?)+(/[^\s]*)?)"
|
||||
urlRegex = re"((https?|ftp)://(-\.)?([^\s/?\.#]+\.?)+(/[^\s\)]*)?)"
|
||||
emailRegex = re"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)"
|
||||
usernameRegex = re"(^|[^\S\n]|\.|>)@([A-z0-9_]+)"
|
||||
usernameRegex = re"(^|[^\S]|\.|>)@([A-z0-9_]+)"
|
||||
picRegex = re"pic.twitter.com/[^ ]+"
|
||||
cardRegex = re"(https?://)?cards.twitter.com/[^ ]+"
|
||||
ellipsisRegex = re" ?…"
|
||||
|
@ -52,10 +52,9 @@ proc linkifyText*(text: string): string =
|
|||
result = result.replace(ellipsisRegex, "")
|
||||
result = result.replace(emailRegex, reEmailToLink)
|
||||
result = result.replace(urlRegex, reUrlToLink)
|
||||
result = result.replace("\n", "<br>")
|
||||
result = result.replace(usernameRegex, reUsernameToLink)
|
||||
result = result.replace(re"([^\s\(\n])<a", "$1 <a")
|
||||
result = result.replace(re"</a>\s+([;.,!\)']|')", "</a>$1")
|
||||
result = result.replace(re"([^\s\(\n%])<a", "$1 <a")
|
||||
result = result.replace(re"</a>\s+([;.,!\)'%]|')", "</a>$1")
|
||||
|
||||
proc stripTwitterUrls*(text: string): string =
|
||||
result = text
|
||||
|
|
Loading…
Reference in a new issue