From a6e87558631ffdc6955cf7dbc47b319fdfd8c976 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 9 Apr 2019 13:45:55 +0700 Subject: [PATCH] do not link inside `
` and ``

---
 lib/auto_linker/parser.ex | 12 ++++++++++++
 test/parser_test.exs      | 11 +++++++++++
 2 files changed, 23 insertions(+)

diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex
index 9e4941f..d16ea9f 100644
--- a/lib/auto_linker/parser.ex
+++ b/lib/auto_linker/parser.ex
@@ -162,9 +162,21 @@ defmodule AutoLinker.Parser do
   defp do_parse({" text, user_acc}, opts, {buffer, acc, :parsing}, handler),
     do: do_parse({text, user_acc}, opts, {"", acc <> buffer <> " text, user_acc}, opts, {buffer, acc, :parsing}, handler),
+    do: do_parse({text, user_acc}, opts, {"", acc <> buffer <> " text, user_acc}, opts, {buffer, acc, :parsing}, handler),
+    do: do_parse({text, user_acc}, opts, {"", acc <> buffer <> "" <> text, user_acc}, opts, {buffer, acc, :skip}, handler),
     do: do_parse({text, user_acc}, opts, {"", acc <> buffer <> "", :parsing}, handler)
 
+  defp do_parse({"
" <> text, user_acc}, opts, {buffer, acc, :skip}, handler), + do: do_parse({text, user_acc}, opts, {"", acc <> buffer <> "", :parsing}, handler) + + defp do_parse({"" <> text, user_acc}, opts, {buffer, acc, :skip}, handler), + do: do_parse({text, user_acc}, opts, {"", acc <> buffer <> "", :parsing}, handler) + defp do_parse({"<" <> text, user_acc}, opts, {"", acc, :parsing}, handler), do: do_parse({text, user_acc}, opts, {"<", acc, {:open, 1}}, handler) diff --git a/test/parser_test.exs b/test/parser_test.exs index 4e23ff0..2bcf788 100644 --- a/test/parser_test.exs +++ b/test/parser_test.exs @@ -69,6 +69,17 @@ defmodule AutoLinker.ParserTest do assert parse(text) == text end + test "does not link inside `
` and ``" do
+      text = "
google.com
" + assert parse(text) == text + + text = "google.com" + assert parse(text) == text + + text = "
google.com
" + assert parse(text) == text + end + test "links url inside html" do text = "
google.com
"