Fix formatting

This commit is contained in:
Justin Tormey 2020-07-27 12:46:26 -05:00
parent b1f6c04eef
commit 1d52bfeb81
2 changed files with 39 additions and 8 deletions

View file

@ -189,7 +189,7 @@ defmodule Linkify.Parser do
buffer
|> String.split(url)
|> 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
else
:nomatch
@ -336,13 +336,13 @@ defmodule Linkify.Parser do
defp link(buffer, opts, user_acc) do
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
check_and_link_reducer(type, buffer, opts, user_acc)
else
{:cont, {buffer, user_acc}}
end
end
end)
end
defp check_and_link_reducer(type, buffer, opts, user_acc) do

View file

@ -14,7 +14,13 @@ defmodule LinkifyTest do
test "default link safe iodata" do
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
test "does on link existing links" do
@ -37,8 +43,17 @@ defmodule LinkifyTest do
test "all kinds of links iodata" do
text = "hello google.com https://ddg.com user@email.com irc:///mIRC"
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>"]]
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>"]
]
assert Linkify.link_to_iodata(text,
email: true,
@ -53,7 +68,15 @@ defmodule LinkifyTest do
test "class attribute iodata" do
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
test "rel attribute" do
@ -63,7 +86,15 @@ defmodule LinkifyTest do
test "rel attribute iodata" do
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
test "rel as function" do