diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex index 14cb785..2e8a97b 100644 --- a/lib/auto_linker/parser.ex +++ b/lib/auto_linker/parser.ex @@ -100,10 +100,10 @@ defmodule AutoLinker.Parser do |> do_parse(Map.delete(opts, :phone)) end - defp do_parse(input, %{mention: true} = opts) do + defp do_parse(input, %{hashtag: true} = opts) do input - |> do_parse(opts, {"", "", :parsing}, &check_and_link_mention/3) - |> do_parse(Map.delete(opts, :mention)) + |> do_parse(opts, {"", "", :parsing}, &check_and_link_hashtag/3) + |> do_parse(Map.delete(opts, :hashtag)) end defp do_parse(input, %{extra: true} = opts) do @@ -144,10 +144,10 @@ defmodule AutoLinker.Parser do do_parse(input, Map.delete(opts, :url)) end - defp do_parse(input, %{hashtag: true} = opts) do + defp do_parse(input, %{mention: true} = opts) do input - |> do_parse(opts, {"", "", :parsing}, &check_and_link_hashtag/3) - |> do_parse(Map.delete(opts, :hashtag)) + |> do_parse(opts, {"", "", :parsing}, &check_and_link_mention/3) + |> do_parse(Map.delete(opts, :mention)) end defp do_parse(input, _), do: input diff --git a/test/auto_linker_test.exs b/test/auto_linker_test.exs index fc6f64d..7ac672e 100644 --- a/test/auto_linker_test.exs +++ b/test/auto_linker_test.exs @@ -100,6 +100,25 @@ defmodule AutoLinkerTest do assert MapSet.to_list(tags) == ["#hello", "#world"] end + + test "mention handler and hashtag prefix" do + text = + "Hello again, @user.<script></script>\nThis is on another :moominmamma: line. #2hu #epic #phantasmagoric" + + handler = fn "@" <> user = mention, _, _, _ -> + ~s(@#{mention}) + end + + expected = + "Hello again, @@user.<script></script>\nThis is on another :moominmamma: line. #2hu #epic #phantasmagoric" + + assert AutoLinker.link(text, + mention: true, + mention_handler: handler, + hashtag: true, + hashtag_prefix: "/tag/" + ) == expected + end end describe "mentions" do