Manually compare tag type for candidate

The match? method is no longer available starting Floki 0.15.0.
This commit is contained in:
Adlan Razalan 2017-10-28 17:38:57 +08:00
parent d409c3f74d
commit 9e43c454e7
1 changed files with 3 additions and 11 deletions

View File

@ -79,9 +79,9 @@ defmodule Readability.Helper do
Check html_tree can be candidate or not.
"""
@spec candidate_tag?(html_tree) :: boolean
def candidate_tag?(html_tree) do
Enum.any?(candidates_selector(), fn(selector) ->
Floki.Selector.match?(html_tree, selector)
def candidate_tag?({tag, _, _} = html_tree) do
Enum.any?(["p", "td"], fn(candidate_tag) ->
tag == candidate_tag
&& (text_length(html_tree)) >= Readability.default_options[:min_text_length]
end)
end
@ -99,12 +99,4 @@ defmodule Readability.Helper do
|> Floki.parse
|> Floki.filter_out(:comment)
end
defp candidates_selector do
["p", "td"]
|> Enum.map(fn(s) ->
tokens = Floki.SelectorTokenizer.tokenize(s)
Floki.SelectorParser.parse(tokens)
end)
end
end