From 55636e859391bceec705b7152e25b65125d1879e Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 9 Apr 2019 14:32:30 +0700 Subject: [PATCH] fix links inside nested html --- lib/auto_linker/parser.ex | 4 ++++ test/parser_test.exs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex index d16ea9f..89c1c62 100644 --- a/lib/auto_linker/parser.ex +++ b/lib/auto_linker/parser.ex @@ -180,6 +180,10 @@ defmodule AutoLinker.Parser do defp do_parse({"<" <> text, user_acc}, opts, {"", acc, :parsing}, handler), do: do_parse({text, user_acc}, opts, {"<", acc, {:open, 1}}, handler) + defp do_parse({"<" <> text, user_acc}, opts, {"", acc, {:html, level}}, handler) do + do_parse({text, user_acc}, opts, {"<", acc, {:open, level + 1}}, handler) + end + defp do_parse({">" <> text, user_acc}, opts, {buffer, acc, {:attrs, level}}, handler), do: do_parse( diff --git a/test/parser_test.exs b/test/parser_test.exs index 2bcf788..a5f0c29 100644 --- a/test/parser_test.exs +++ b/test/parser_test.exs @@ -95,6 +95,12 @@ defmodule AutoLinker.ParserTest do assert parse(text, class: false, rel: false, new_window: false) == expected end + test "links url inside nested html" do + text = "

google.com

" + expected = "

google.com

" + assert parse(text, class: false, rel: false, new_window: false) == expected + end + test "excludes html with specified class" do text = "```Check out
google.com
```" assert parse(text, exclude_patterns: ["```"]) == text