fix regression with phone and markdown
This commit is contained in:
parent
4d5182ec1f
commit
0d72ff37a4
2 changed files with 12 additions and 5 deletions
|
@ -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, %{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
|
||||
text
|
||||
|> do_parse(false, opts, {"", "", :parsing}, &check_and_link_phone/3)
|
||||
|> do_parse(Map.delete(opts, :phone))
|
||||
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
|
||||
if (exclude = Map.get(opts, :exclude_pattern, false)) && String.starts_with?(text, exclude) do
|
||||
text
|
||||
|
|
|
@ -23,4 +23,10 @@ defmodule AutoLinkerTest do
|
|||
"<a href='http://google.com'>google.com</a>"
|
||||
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
|
||||
|
|
Reference in a new issue