logo

auto_linker

AutoLinker-shim, based on https://git.pleroma.social/pleroma/auto_linker git clone https://hacktivis.me/git/auto_linker.git
commit: 55636e859391bceec705b7152e25b65125d1879e
parent a6e87558631ffdc6955cf7dbc47b319fdfd8c976
Author: Egor Kislitsyn <egor@kislitsyn.com>
Date:   Tue,  9 Apr 2019 14:32:30 +0700

fix links inside nested html

Diffstat:

Mlib/auto_linker/parser.ex4++++
Mtest/parser_test.exs6++++++
2 files changed, 10 insertions(+), 0 deletions(-)

diff --git 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 @@ -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 = "<p><strong>google.com</strong></p>" + expected = "<p><strong><a href=\"http://google.com\">google.com</a></strong></p>" + assert parse(text, class: false, rel: false, new_window: false) == expected + end + test "excludes html with specified class" do text = "```Check out <div class='section'>google.com</div>```" assert parse(text, exclude_patterns: ["```"]) == text