text, user_acc}, opts, {buffer, acc, :parsing}, handler),
+ do: do_parse({text, user_acc}, opts, {"", acc <> buffer <> "" <> text, user_acc}, opts, {buffer, acc, :skip}, handler),
do: do_parse({text, user_acc}, opts, {"", acc <> buffer <> "
", :parsing}, handler)
+ defp do_parse({"" <> text, user_acc}, opts, {buffer, acc, :skip}, handler),
+ do: do_parse({text, user_acc}, opts, {"", acc <> buffer <> "", :parsing}, handler)
+
+ defp do_parse({"" <> text, user_acc}, opts, {buffer, acc, :skip}, handler),
+ do: do_parse({text, user_acc}, opts, {"", acc <> buffer <> "", :parsing}, handler)
+
defp do_parse({"<" <> text, user_acc}, opts, {"", acc, :parsing}, handler),
do: do_parse({text, user_acc}, opts, {"<", acc, {:open, 1}}, handler)
+ defp do_parse({"<" <> text, user_acc}, opts, {"", acc, {:html, level}}, handler) do
+ do_parse({text, user_acc}, opts, {"<", acc, {:open, level + 1}}, handler)
+ end
+
defp do_parse({">" <> text, user_acc}, opts, {buffer, acc, {:attrs, level}}, handler),
do:
do_parse(
@@ -204,19 +215,8 @@ defmodule AutoLinker.Parser do
handler
)
- defp do_parse(
- {<hello world
\n<`em>another @user__test and @user__test google.com paragraph
\n" + + expected = + "hello world
\n<`em>another @user__test and @user__test google.com paragraph
\n" + + assert AutoLinker.link(text, + mention: true, + mention_prefix: "u/", + class: false, + rel: false, + new_window: false + ) == expected + end + test "metion @user@example.com" do text = "hey @user@example.com" diff --git a/test/builder_test.exs b/test/builder_test.exs index 0742bd6..e20f6ea 100644 --- a/test/builder_test.exs +++ b/test/builder_test.exs @@ -17,6 +17,16 @@ defmodule AutoLinker.BuilderTest do "text" assert create_link("text", %{rel: "me"}) == expected + + expected = "t..." + + assert create_link("text", %{truncate: 3, rel: false}) == expected + + expected = "text" + assert create_link("text", %{truncate: 2, rel: false}) == expected + + expected = "http://text" + assert create_link("http://text", %{rel: false, strip_prefix: false}) == expected end test "create_markdown_links/2" do @@ -52,9 +62,9 @@ defmodule AutoLinker.BuilderTest do phrase = "my exten is x888. Call me." expected = - ~s'my exten is x888. Call me.' + ~s'my exten is x888. Call me.' - assert create_phone_link([["x888", ""]], phrase, []) == expected + assert create_phone_link([["x888", ""]], phrase, attributes: [test: "test"]) == expected end test "handles multiple links" do diff --git a/test/parser_test.exs b/test/parser_test.exs index 66bfb97..da68edc 100644 --- a/test/parser_test.exs +++ b/test/parser_test.exs @@ -69,7 +69,24 @@ defmodule AutoLinker.ParserTest do assert parse(text) == text end + test "does not link inside `` and ``" do
+ text = "google.com
"
+ assert parse(text) == text
+
+ text = "google.com
"
+ assert parse(text) == text
+
+ text = "google.com
"
+ assert parse(text) == text
+ end
+
test "links url inside html" do
+ text = "google.com"
+
+ expected = ""
+
+ assert parse(text, class: false, rel: false, new_window: false, phone: false) == expected
+
text = "Check out google.com"
expected =
@@ -78,10 +95,21 @@ defmodule AutoLinker.ParserTest do
assert parse(text, class: false, rel: false, new_window: false) == expected
end
+ test "links url inside nested html" do
+ text = "google.com
"
+ expected = ""
+ assert parse(text, class: false, rel: false, new_window: false) == expected
+ end
+
test "excludes html with specified class" do
text = "```Check out google.com```"
assert parse(text, exclude_patterns: ["```"]) == text
end
+
+ test "do not link urls" do
+ text = "google.com"
+ assert parse(text, url: false, phone: true) == text
+ end
end
def valid_number?([list], number) do