fix regression with phone and markdown

This commit is contained in:
Stephen M. Pallen 2018-01-22 20:59:52 -05:00
parent 4d5182ec1f
commit 0d72ff37a4
2 changed files with 12 additions and 5 deletions

View file

@ -62,17 +62,18 @@ defmodule AutoLinker.Parser do
defp do_parse(text, %{phone: false} = opts), do: do_parse(text, Map.delete(opts, :phone)) defp do_parse(text, %{phone: false} = opts), do: do_parse(text, Map.delete(opts, :phone))
defp do_parse(text, %{url: false} = opts), do: do_parse(text, Map.delete(opts, :url)) defp do_parse(text, %{url: false} = opts), do: do_parse(text, Map.delete(opts, :url))
defp do_parse(text, %{markdown: true} = opts) do
text
|> Builder.create_markdown_links(opts)
|> do_parse(Map.delete(opts, :markdown))
end
defp do_parse(text, %{phone: _} = opts) do defp do_parse(text, %{phone: _} = opts) do
text text
|> do_parse(false, opts, {"", "", :parsing}, &check_and_link_phone/3) |> do_parse(false, opts, {"", "", :parsing}, &check_and_link_phone/3)
|> do_parse(Map.delete(opts, :phone)) |> do_parse(Map.delete(opts, :phone))
end end
defp do_parse(text, %{markdown: true} = opts) do
text
|> Builder.create_markdown_links(opts)
|> do_parse(Map.delete(opts, :markdown))
end
defp do_parse(text, %{url: _} = opts) do defp do_parse(text, %{url: _} = opts) do
if (exclude = Map.get(opts, :exclude_pattern, false)) && String.starts_with?(text, exclude) do if (exclude = Map.get(opts, :exclude_pattern, false)) && String.starts_with?(text, exclude) do
text text

View file

@ -23,4 +23,10 @@ defmodule AutoLinkerTest do
"<a href='http://google.com'>google.com</a>" "<a href='http://google.com'>google.com</a>"
end end
test "phone number and markdown link" do
assert AutoLinker.link("888 888-8888 [ab](a.com)", phone: true, markdown: true) ==
"<a href=\"#\" class=\"phone-number\" data-phone=\"8888888888\">888 888-8888</a>" <>
" <a href='a.com' class='auto-linker' target='_blank' rel='noopener noreferrer'>ab</a>"
end
end end