Browse Source

improve mentions matching

merge-requests/2/head
Egor Kislitsyn 5 years ago
parent
commit
056d7f2f37
2 changed files with 3 additions and 19 deletions
  1. +1
    -1
      lib/auto_linker/parser.ex
  2. +2
    -18
      test/auto_linker_test.exs

+ 1
- 1
lib/auto_linker/parser.ex View File

@ -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


+ 2
- 18
test/auto_linker_test.exs View File

@ -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…
Cancel
Save