Browse Source

fix parsing inside HTML tags

merge-requests/10/head
Egor Kislitsyn 5 years ago
parent
commit
4949c02cb6
3 changed files with 31 additions and 13 deletions
  1. +2
    -13
      lib/auto_linker/parser.ex
  2. +16
    -0
      test/auto_linker_test.exs
  3. +13
    -0
      test/parser_test.exs

+ 2
- 13
lib/auto_linker/parser.ex View File

@ -204,19 +204,8 @@ defmodule AutoLinker.Parser do
handler
)
defp do_parse(
{<<char::bytes-size(1), text::binary>>, user_acc},
opts,
{buffer, acc, {:open, level}},
handler
)
when char in [" ", "\r", "\n"] do
do_parse(
{text, user_acc},
opts,
{"", acc <> buffer <> char, {:attrs, level}},
handler
)
defp do_parse({text, user_acc}, opts, {buffer, acc, {:open, level}}, handler) do
do_parse({text, user_acc}, opts, {"", acc <> buffer, {:attrs, level}}, handler)
end
# default cases where state is not important


+ 16
- 0
test/auto_linker_test.exs View File

@ -144,6 +144,22 @@ defmodule AutoLinkerTest do
) == expected
end
test "mentions inside html tags" do
text =
"<p><strong>hello world</strong></p>\n<p><`em>another @user__test and @user__test google.com paragraph</em></p>\n"
expected =
"<p><strong>hello world</strong></p>\n<p><`em>another <a href=\"u/user__test\">@user__test</a> and <a href=\"u/user__test\">@user__test</a> <a href=\"http://google.com\">google.com</a> paragraph</em></p>\n"
assert AutoLinker.link(text,
mention: true,
mention_prefix: "u/",
class: false,
rel: false,
new_window: false
) == expected
end
test "metion @user@example.com" do
text = "hey @user@example.com"


+ 13
- 0
test/parser_test.exs View File

@ -70,6 +70,19 @@ defmodule AutoLinker.ParserTest do
end
test "links url inside html" do
text = "<div>google.com</div>"
expected = "<div><a href=\"http://google.com\">google.com</a></div>"
assert parse(text, class: false, rel: false, new_window: false) == expected
text = "Check out <div class='section'>google.com</div>"
expected =
"Check out <div class='section'><a href=\"http://google.com\">google.com</a></div>"
assert parse(text, class: false, rel: false, new_window: false) == expected
end
text = "Check out <div class='section'>google.com</div>"
expected =


Loading…
Cancel
Save