From 11d9657bddde8d214f5f36c36794a758540b27be Mon Sep 17 00:00:00 2001 From: Jan Lukas Gernert Date: Sun, 12 Mar 2023 14:20:19 +0100 Subject: [PATCH] fix using parent if top candidate is only child --- src/full_text_parser/readability/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/full_text_parser/readability/mod.rs b/src/full_text_parser/readability/mod.rs index 999ff41..dd2e43f 100644 --- a/src/full_text_parser/readability/mod.rs +++ b/src/full_text_parser/readability/mod.rs @@ -394,7 +394,7 @@ impl Readability { // joining logic when adjacent content is actually located in parent's sibling node. parent_of_top_candidate = top_candidate.get_parent(); - while Util::has_tag_name(parent_of_top_candidate.as_ref(), "BODY") + while !Util::has_tag_name(parent_of_top_candidate.as_ref(), "BODY") && parent_of_top_candidate .as_ref() .map(|n| n.get_child_elements().len() == 1) @@ -422,10 +422,10 @@ impl Readability { parent_of_top_candidate = top_candidate.get_parent(); let siblings = parent_of_top_candidate .as_ref() - .map(|n| n.get_child_nodes()); + .map(|n| n.get_child_elements()); - if let Some(siblings) = siblings { - for mut sibling in siblings { + if let Some(mut siblings) = siblings { + for mut sibling in siblings.drain(..) { let mut append = false; let score = Self::get_content_score(&sibling).unwrap_or(0.0);