improve mentions matching
This commit is contained in:
parent
8f7496b1d3
commit
056d7f2f37
2 changed files with 3 additions and 19 deletions
|
@ -40,7 +40,7 @@ defmodule AutoLinker.Parser do
|
|||
|
||||
# @user
|
||||
# @user@example.com
|
||||
@match_mention ~r/^@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@?[a-zA-Z0-9_-](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u
|
||||
@match_mention ~r/^@[a-zA-Z\d_-]+@[a-zA-Z0-9_-](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*|@[a-zA-Z\d_-]+/u
|
||||
|
||||
# https://www.w3.org/TR/html5/forms.html#valid-e-mail-address
|
||||
@match_email ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/u
|
||||
|
|
|
@ -30,19 +30,15 @@ defmodule AutoLinkerTest do
|
|||
|
||||
test "all kinds of links" do
|
||||
text =
|
||||
"hello @user google.com https://ddg.com 888 888-8888 #tag user@email.com [google.com](http://google.com) irc:///mIRC"
|
||||
"hello google.com https://ddg.com 888 888-8888 user@email.com [google.com](http://google.com) irc:///mIRC"
|
||||
|
||||
expected =
|
||||
"hello <a href=\"https://example.com/user/user\">@user</a> <a href=\"http://google.com\">google.com</a> <a href=\"https://ddg.com\">ddg.com</a> <a href=\"#\" class=\"phone-number\" data-phone=\"8888888888\">888 888-8888</a> <a href=\"https://example.com/tag/tag\">#tag</a> <a href=\"mailto:user@email.com\" >user@email.com</a> <a href='http://google.com'>google.com</a> <a href=\"irc:///mIRC\">irc:///mIRC</a>"
|
||||
"hello <a href=\"http://google.com\">google.com</a> <a href=\"https://ddg.com\">ddg.com</a> <a href=\"#\" class=\"phone-number\" data-phone=\"8888888888\">888 888-8888</a> <a href=\"mailto:user@email.com\" >user@email.com</a> <a href='http://google.com'>google.com</a> <a href=\"irc:///mIRC\">irc:///mIRC</a>"
|
||||
|
||||
assert AutoLinker.link(text,
|
||||
phone: true,
|
||||
markdown: true,
|
||||
email: true,
|
||||
mention: true,
|
||||
mention_prefix: "https://example.com/user/",
|
||||
hashtag: true,
|
||||
hashtag_prefix: "https://example.com/tag/",
|
||||
scheme: true,
|
||||
extra: true,
|
||||
class: false,
|
||||
|
@ -143,18 +139,6 @@ defmodule AutoLinkerTest do
|
|||
mention_prefix: "https://example.com/user/"
|
||||
) == expected
|
||||
end
|
||||
|
||||
test "skip if starts with @@" do
|
||||
text = "hello @@user and @anotherUser"
|
||||
|
||||
expected =
|
||||
"hello @@user and <a href='https://example.com/user/anotherUser' class='auto-linker' target='_blank' rel='noopener noreferrer'>@anotherUser</a>"
|
||||
|
||||
assert AutoLinker.link(text,
|
||||
mention: true,
|
||||
mention_prefix: "https://example.com/user/"
|
||||
) == expected
|
||||
end
|
||||
end
|
||||
|
||||
describe "hashtag links" do
|
||||
|
|
Loading…
Reference in a new issue