Fix formatting
This commit is contained in:
parent
b1f6c04eef
commit
1d52bfeb81
2 changed files with 39 additions and 8 deletions
|
@ -189,7 +189,7 @@ defmodule Linkify.Parser do
|
||||||
buffer
|
buffer
|
||||||
|> String.split(url)
|
|> String.split(url)
|
||||||
|> Enum.intersperse(link_url(url, opts))
|
|> Enum.intersperse(link_url(url, opts))
|
||||||
|> (if opts[:iodata], do: & &1, else: & Enum.join(&1)).()
|
|> if(opts[:iodata], do: & &1, else: &Enum.join(&1)).()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
:nomatch
|
:nomatch
|
||||||
|
@ -336,13 +336,13 @@ defmodule Linkify.Parser do
|
||||||
defp link(buffer, opts, user_acc) do
|
defp link(buffer, opts, user_acc) do
|
||||||
opts_list = Map.to_list(opts)
|
opts_list = Map.to_list(opts)
|
||||||
|
|
||||||
Enum.reduce_while @types, {buffer, user_acc}, fn type, _ ->
|
Enum.reduce_while(@types, {buffer, user_acc}, fn type, _ ->
|
||||||
if {type, true} in opts_list do
|
if {type, true} in opts_list do
|
||||||
check_and_link_reducer(type, buffer, opts, user_acc)
|
check_and_link_reducer(type, buffer, opts, user_acc)
|
||||||
else
|
else
|
||||||
{:cont, {buffer, user_acc}}
|
{:cont, {buffer, user_acc}}
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp check_and_link_reducer(type, buffer, opts, user_acc) do
|
defp check_and_link_reducer(type, buffer, opts, user_acc) do
|
||||||
|
|
|
@ -14,7 +14,13 @@ defmodule LinkifyTest do
|
||||||
|
|
||||||
test "default link safe iodata" do
|
test "default link safe iodata" do
|
||||||
assert Linkify.link_safe("google.com") ==
|
assert Linkify.link_safe("google.com") ==
|
||||||
[[{:safe, ["<a ", "href=\"http://google.com\"", ">"]}, "google.com", {:safe, "</a>"}]]
|
[
|
||||||
|
[
|
||||||
|
{:safe, ["<a ", "href=\"http://google.com\"", ">"]},
|
||||||
|
"google.com",
|
||||||
|
{:safe, "</a>"}
|
||||||
|
]
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does on link existing links" do
|
test "does on link existing links" do
|
||||||
|
@ -37,8 +43,17 @@ defmodule LinkifyTest do
|
||||||
test "all kinds of links iodata" do
|
test "all kinds of links iodata" do
|
||||||
text = "hello google.com https://ddg.com user@email.com irc:///mIRC"
|
text = "hello google.com https://ddg.com user@email.com irc:///mIRC"
|
||||||
|
|
||||||
expected =
|
expected = [
|
||||||
["hello", " ", ["<a ", "href=\"http://google.com\"", ">", "google.com", "</a>"], " ", ["<a ", "href=\"https://ddg.com\"", ">", "https://ddg.com", "</a>"], " ", ["<a ", "href=\"mailto:user@email.com\"", ">", "user@email.com", "</a>"], " ", ["<a ", "href=\"irc:///mIRC\"", ">", "irc:///mIRC", "</a>"]]
|
"hello",
|
||||||
|
" ",
|
||||||
|
["<a ", "href=\"http://google.com\"", ">", "google.com", "</a>"],
|
||||||
|
" ",
|
||||||
|
["<a ", "href=\"https://ddg.com\"", ">", "https://ddg.com", "</a>"],
|
||||||
|
" ",
|
||||||
|
["<a ", "href=\"mailto:user@email.com\"", ">", "user@email.com", "</a>"],
|
||||||
|
" ",
|
||||||
|
["<a ", "href=\"irc:///mIRC\"", ">", "irc:///mIRC", "</a>"]
|
||||||
|
]
|
||||||
|
|
||||||
assert Linkify.link_to_iodata(text,
|
assert Linkify.link_to_iodata(text,
|
||||||
email: true,
|
email: true,
|
||||||
|
@ -53,7 +68,15 @@ defmodule LinkifyTest do
|
||||||
|
|
||||||
test "class attribute iodata" do
|
test "class attribute iodata" do
|
||||||
assert Linkify.link_to_iodata("google.com", class: "linkified") ==
|
assert Linkify.link_to_iodata("google.com", class: "linkified") ==
|
||||||
[["<a ", "href=\"http://google.com\" class=\"linkified\"", ">", "google.com", "</a>"]]
|
[
|
||||||
|
[
|
||||||
|
"<a ",
|
||||||
|
"href=\"http://google.com\" class=\"linkified\"",
|
||||||
|
">",
|
||||||
|
"google.com",
|
||||||
|
"</a>"
|
||||||
|
]
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rel attribute" do
|
test "rel attribute" do
|
||||||
|
@ -63,7 +86,15 @@ defmodule LinkifyTest do
|
||||||
|
|
||||||
test "rel attribute iodata" do
|
test "rel attribute iodata" do
|
||||||
assert Linkify.link_to_iodata("google.com", rel: "noopener noreferrer") ==
|
assert Linkify.link_to_iodata("google.com", rel: "noopener noreferrer") ==
|
||||||
[["<a ", "href=\"http://google.com\" rel=\"noopener noreferrer\"", ">", "google.com", "</a>"]]
|
[
|
||||||
|
[
|
||||||
|
"<a ",
|
||||||
|
"href=\"http://google.com\" rel=\"noopener noreferrer\"",
|
||||||
|
">",
|
||||||
|
"google.com",
|
||||||
|
"</a>"
|
||||||
|
]
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rel as function" do
|
test "rel as function" do
|
||||||
|
|
Reference in a new issue