From 9e43c454e78e69f1c3594c99ddd11307f31d221c Mon Sep 17 00:00:00 2001 From: Adlan Razalan Date: Sat, 28 Oct 2017 17:38:57 +0800 Subject: [PATCH] Manually compare tag type for candidate The match? method is no longer available starting Floki 0.15.0. --- lib/readability/helper.ex | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/readability/helper.ex b/lib/readability/helper.ex index 1746812..012ee79 100644 --- a/lib/readability/helper.ex +++ b/lib/readability/helper.ex @@ -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