From 0d72ff37a4c28c1a80b4b0f198c082cd8990ad73 Mon Sep 17 00:00:00 2001 From: "Stephen M. Pallen" Date: Mon, 22 Jan 2018 20:59:52 -0500 Subject: [PATCH] fix regression with phone and markdown --- lib/auto_linker/parser.ex | 11 ++++++----- test/auto_linker_test.exs | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex index 946ae1d..8a0522d 100644 --- a/lib/auto_linker/parser.ex +++ b/lib/auto_linker/parser.ex @@ -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 diff --git a/test/auto_linker_test.exs b/test/auto_linker_test.exs index 079ddb7..1ffb972 100644 --- a/test/auto_linker_test.exs +++ b/test/auto_linker_test.exs @@ -23,4 +23,10 @@ defmodule AutoLinkerTest do "google.com" end + test "phone number and markdown link" do + assert AutoLinker.link("888 888-8888 [ab](a.com)", phone: true, markdown: true) == + "888 888-8888" <> + " ab" + end + end