Browse Source

fix links inside nested html

merge-requests/10/head
Egor Kislitsyn 5 years ago
parent
commit
55636e8593
2 changed files with 10 additions and 0 deletions
  1. +4
    -0
      lib/auto_linker/parser.ex
  2. +6
    -0
      test/parser_test.exs

+ 4
- 0
lib/auto_linker/parser.ex View File

@ -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(


+ 6
- 0
test/parser_test.exs View File

@ -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


Loading…
Cancel
Save