From 38c38a772fa6154169e3e5b34c89e2b6fd2ef6bd Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Sun, 4 Jul 2021 15:20:19 -0400 Subject: [PATCH] Find valid parent element when collapsing result content Previously if a result element marked for collapsing didn't have a valid "parent" element, the collapsing was skipped altogether. This loops through child elements until a valid parent is found (or if one isn't found, the element will not be collapsed). --- app/filter.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/filter.py b/app/filter.py index 215bfe7..87d00a2 100644 --- a/app/filter.py +++ b/app/filter.py @@ -173,8 +173,12 @@ class Filter: break # Create the new details element to wrap around the result's - # immediate parent - parent = result_children[0].parent + # first parent + parent = None + idx = 0 + while not parent and idx < len(result_children): + parent = result_children[idx].parent + idx += 1 details = BeautifulSoup(features='html.parser').new_tag('details') summary = BeautifulSoup(features='html.parser').new_tag('summary') summary.string = label