Fix username linkification bug
This commit is contained in:
parent
7a7c4d68e4
commit
3ea926550b
|
@ -8,7 +8,7 @@ from unicode import Rune, `$`
|
||||||
const
|
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-.]+)"
|
emailRegex = re"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)"
|
||||||
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" ?…"
|
||||||
hashtagRegex = re"([^\S])?([#$][A-z0-9]+)"
|
hashtagRegex = re"([^\S])?([#$][A-z0-9]+)"
|
||||||
|
@ -79,13 +79,13 @@ proc linkifyText*(text: string; prefs: Prefs; rss=false): string =
|
||||||
result = xmltree.escape(stripText(text))
|
result = xmltree.escape(stripText(text))
|
||||||
result = result.replace(ellipsisRegex, " ")
|
result = result.replace(ellipsisRegex, " ")
|
||||||
result = result.replace(emailRegex, reEmailToLink)
|
result = result.replace(emailRegex, reEmailToLink)
|
||||||
result = result.replace(hashtagRegex, reHashtagToLink)
|
|
||||||
if rss:
|
if rss:
|
||||||
result = result.replace(urlRegex, reUrlToLink)
|
result = result.replace(urlRegex, reUrlToLink)
|
||||||
result = result.replace(usernameRegex, reUsernameToFullLink)
|
result = result.replace(usernameRegex, reUsernameToFullLink)
|
||||||
else:
|
else:
|
||||||
result = result.replace(urlRegex, reUrlToShortLink)
|
result = result.replace(urlRegex, reUrlToShortLink)
|
||||||
result = result.replace(usernameRegex, reUsernameToLink)
|
result = result.replace(usernameRegex, reUsernameToLink)
|
||||||
|
result = result.replace(hashtagRegex, reHashtagToLink)
|
||||||
result = result.replace(re"([^\s\(\n%])<a", "$1 <a")
|
result = result.replace(re"([^\s\(\n%])<a", "$1 <a")
|
||||||
result = result.replace(re"</a>\s+([;.,!\)'%]|')", "</a>$1")
|
result = result.replace(re"</a>\s+([;.,!\)'%]|')", "</a>$1")
|
||||||
result = result.replace(re"^\. <a", ".<a")
|
result = result.replace(re"^\. <a", ".<a")
|
||||||
|
|
Loading…
Reference in New Issue