logo

auto_linker

AutoLinker-shim, based on https://git.pleroma.social/pleroma/auto_linker git clone https://hacktivis.me/git/auto_linker.git
commit: 1d52bfeb81d866bb1e42b81c983af6f68d4c3164
parent b1f6c04eefa67c891d05f87a54ccc41b41b2d2b0
Author: Justin Tormey <jrtormey@gmail.com>
Date:   Mon, 27 Jul 2020 12:46:26 -0500

Fix formatting

Diffstat:

Mlib/linkify/parser.ex6+++---
Mtest/linkify_test.exs41++++++++++++++++++++++++++++++++++++-----
2 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/lib/linkify/parser.ex b/lib/linkify/parser.ex @@ -189,7 +189,7 @@ defmodule Linkify.Parser do buffer |> String.split(url) |> Enum.intersperse(link_url(url, opts)) - |> (if opts[:iodata], do: & &1, else: & Enum.join(&1)).() + |> if(opts[:iodata], do: & &1, else: &Enum.join(&1)).() end else :nomatch @@ -336,13 +336,13 @@ defmodule Linkify.Parser do defp link(buffer, opts, user_acc) do opts_list = Map.to_list(opts) - Enum.reduce_while @types, {buffer, user_acc}, fn type, _ -> + Enum.reduce_while(@types, {buffer, user_acc}, fn type, _ -> if {type, true} in opts_list do check_and_link_reducer(type, buffer, opts, user_acc) else {:cont, {buffer, user_acc}} end - end + end) end defp check_and_link_reducer(type, buffer, opts, user_acc) do diff --git a/test/linkify_test.exs b/test/linkify_test.exs @@ -14,7 +14,13 @@ defmodule LinkifyTest do test "default link safe iodata" do assert Linkify.link_safe("google.com") == - [[{:safe, ["<a ", "href=\"http://google.com\"", ">"]}, "google.com", {:safe, "</a>"}]] + [ + [ + {:safe, ["<a ", "href=\"http://google.com\"", ">"]}, + "google.com", + {:safe, "</a>"} + ] + ] end test "does on link existing links" do @@ -37,8 +43,17 @@ defmodule LinkifyTest do test "all kinds of links iodata" do text = "hello google.com https://ddg.com user@email.com irc:///mIRC" - expected = - ["hello", " ", ["<a ", "href=\"http://google.com\"", ">", "google.com", "</a>"], " ", ["<a ", "href=\"https://ddg.com\"", ">", "https://ddg.com", "</a>"], " ", ["<a ", "href=\"mailto:user@email.com\"", ">", "user@email.com", "</a>"], " ", ["<a ", "href=\"irc:///mIRC\"", ">", "irc:///mIRC", "</a>"]] + expected = [ + "hello", + " ", + ["<a ", "href=\"http://google.com\"", ">", "google.com", "</a>"], + " ", + ["<a ", "href=\"https://ddg.com\"", ">", "https://ddg.com", "</a>"], + " ", + ["<a ", "href=\"mailto:user@email.com\"", ">", "user@email.com", "</a>"], + " ", + ["<a ", "href=\"irc:///mIRC\"", ">", "irc:///mIRC", "</a>"] + ] assert Linkify.link_to_iodata(text, email: true, @@ -53,7 +68,15 @@ defmodule LinkifyTest do test "class attribute iodata" do assert Linkify.link_to_iodata("google.com", class: "linkified") == - [["<a ", "href=\"http://google.com\" class=\"linkified\"", ">", "google.com", "</a>"]] + [ + [ + "<a ", + "href=\"http://google.com\" class=\"linkified\"", + ">", + "google.com", + "</a>" + ] + ] end test "rel attribute" do @@ -63,7 +86,15 @@ defmodule LinkifyTest do test "rel attribute iodata" do assert Linkify.link_to_iodata("google.com", rel: "noopener noreferrer") == - [["<a ", "href=\"http://google.com\" rel=\"noopener noreferrer\"", ">", "google.com", "</a>"]] + [ + [ + "<a ", + "href=\"http://google.com\" rel=\"noopener noreferrer\"", + ">", + "google.com", + "</a>" + ] + ] end test "rel as function" do