From f081e6b5537ea39c3f2aba80db04b070c9b8b73d Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Fri, 21 Jun 2019 17:12:11 +0700 Subject: [PATCH] Remove markdown links support --- README.md | 3 --- lib/auto_linker.ex | 7 ------- lib/auto_linker/builder.ex | 18 ------------------ lib/auto_linker/parser.ex | 7 ------- test/auto_linker_test.exs | 17 ++--------------- test/builder_test.exs | 7 ------- 6 files changed, 2 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index c1b1dcd..142e9d8 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,6 @@ iex> AutoLinker.link("or at home on 555.555.5555", phone: true) iex> AutoLinker.link(", work (555) 555-5555", phone: true) ", work (555) 555-5555" - -iex> AutoLinker.link("[Google Search](http://google.com)", markdown: true) -"Google Search" ``` See the [Docs](https://hexdocs.pm/auto_linker/) for more examples diff --git a/lib/auto_linker.ex b/lib/auto_linker.ex index 01688d8..b4b98a7 100644 --- a/lib/auto_linker.ex +++ b/lib/auto_linker.ex @@ -15,12 +15,6 @@ defmodule AutoLinker do iex> AutoLinker.link("google.com", new_window: false, rel: false, class: false) ~s(google.com) - - iex> AutoLinker.link("[Google](http://google.com)", markdown: true, new_window: false, rel: false, class: false) - ~s(Google) - - iex> AutoLinker.link("[Google Search](http://google.com)", markdown: true) - ~s(Google Search) """ import AutoLinker.Parser @@ -39,7 +33,6 @@ defmodule AutoLinker do * `exclude_class: false` - Set to a class name when you don't want urls auto linked in the html of the give class * `exclude_id: false` - Set to an element id when you don't want urls auto linked in the html of the give element * `exclude_patterns: ["```"]` - Don't link anything between the the pattern - * `markdown: false` - link markdown style links * `email: false` - link email links * `mention: false` - link @mentions (when `true`, requires `mention_prefix` or `mention_handler` options to be set) * `mention_prefix: nil` - a prefix to build a link for a mention (example: `https://example.com/user/`) diff --git a/lib/auto_linker/builder.ex b/lib/auto_linker/builder.ex index 888fd82..e430576 100644 --- a/lib/auto_linker/builder.ex +++ b/lib/auto_linker/builder.ex @@ -17,14 +17,6 @@ defmodule AutoLinker.Builder do |> format_url(text, opts) end - def create_markdown_links(text, opts) do - [] - |> build_attrs(text, opts, :rel) - |> build_attrs(text, opts, :target) - |> build_attrs(text, opts, :class) - |> format_markdown(text, opts) - end - defp build_attrs(attrs, uri, %{rel: get_rel}, :rel) when is_function(get_rel, 1) do case get_rel.(uri) do nil -> attrs @@ -68,16 +60,6 @@ defmodule AutoLinker.Builder do |> Enum.join(" ") end - defp format_markdown(attrs, text, _opts) do - attrs = - case format_attrs(attrs) do - "" -> "" - attrs -> " " <> attrs - end - - Regex.replace(~r/\[(.+?)\]\((.+?)\)/, text, "\\1") - end - defp truncate(url, false), do: url defp truncate(url, len) when len < 3, do: url diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex index b7b4b75..eba051a 100644 --- a/lib/auto_linker/parser.ex +++ b/lib/auto_linker/parser.ex @@ -111,13 +111,6 @@ defmodule AutoLinker.Parser do |> do_parse(Map.delete(opts, :extra)) end - defp do_parse({text, user_acc}, %{markdown: true} = opts) do - text - |> Builder.create_markdown_links(opts) - |> (&{&1, user_acc}).() - |> do_parse(Map.delete(opts, :markdown)) - end - defp do_parse(input, %{email: true} = opts) do input |> do_parse(opts, {"", "", :parsing}, &check_and_link_email/3) diff --git a/test/auto_linker_test.exs b/test/auto_linker_test.exs index 0478c57..489b03e 100644 --- a/test/auto_linker_test.exs +++ b/test/auto_linker_test.exs @@ -12,32 +12,19 @@ defmodule AutoLinkerTest do "google.com" end - test "markdown" do - assert AutoLinker.link("[google.com](http://google.com)", markdown: true) == - "google.com" - end - test "does on link existing links" do assert AutoLinker.link("google.com") == "google.com" end - test "phone number and markdown link" do - assert AutoLinker.link("888 888-8888 [ab](a.com)", phone: true, markdown: true) == - ~s(888 888-8888) <> - ~s( ab) - end - test "all kinds of links" do - text = - "hello google.com https://ddg.com 888 888-8888 user@email.com [google.com](http://google.com) irc:///mIRC" + text = "hello google.com https://ddg.com 888 888-8888 user@email.com irc:///mIRC" expected = - "hello google.com ddg.com 888 888-8888 user@email.com google.com irc:///mIRC" + "hello google.com ddg.com 888 888-8888 user@email.com irc:///mIRC" assert AutoLinker.link(text, phone: true, - markdown: true, email: true, scheme: true, extra: true, diff --git a/test/builder_test.exs b/test/builder_test.exs index e20f6ea..9fd332e 100644 --- a/test/builder_test.exs +++ b/test/builder_test.exs @@ -29,13 +29,6 @@ defmodule AutoLinker.BuilderTest do assert create_link("http://text", %{rel: false, strip_prefix: false}) == expected end - test "create_markdown_links/2" do - expected = - "text" - - assert create_markdown_links("[text](url)", %{}) == expected - end - test "format_hashtag/3" do expected = "#girls" assert format_hashtag(%{href: "/t/girls"}, "girls", nil) == expected