Add ability to collapse "people also ask"
This adds a step in the filter process to wrap the "people also ask" section in a <details> element, which automatically collapses the contents of the section. Clicking/tapping the details element expands the view as normal. See #113main
parent
3978241d28
commit
b695179c79
|
@ -95,9 +95,26 @@ class Filter:
|
||||||
if not self.main_divs:
|
if not self.main_divs:
|
||||||
return
|
return
|
||||||
|
|
||||||
question_divs = [_ for _ in self.main_divs.find_all('div', recursive=False) if len(_.find_all('h2')) > 0]
|
question_divs = [_ for _ in self.main_divs.find_all(
|
||||||
|
'div', recursive=False
|
||||||
|
) if len(_.find_all('h2')) > 0]
|
||||||
|
|
||||||
|
if len(question_divs) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Wrap section in details element to allow collapse/expand
|
||||||
|
details = BeautifulSoup(features='lxml').new_tag('details')
|
||||||
|
summary = BeautifulSoup(features='lxml').new_tag('summary')
|
||||||
|
summary.string = question_divs[0].find('h2').text
|
||||||
|
question_divs[0].find('h2').decompose()
|
||||||
|
details.append(summary)
|
||||||
|
question_divs[0].wrap(details)
|
||||||
|
|
||||||
for question_div in question_divs:
|
for question_div in question_divs:
|
||||||
questions = [_ for _ in question_div.find_all('div', recursive=True) if _.text.endswith('?')]
|
questions = [_ for _ in question_div.find_all(
|
||||||
|
'div', recursive=True
|
||||||
|
) if _.text.endswith('?')]
|
||||||
|
|
||||||
for question in questions:
|
for question in questions:
|
||||||
question['style'] = 'padding: 10px; font-style: italic;'
|
question['style'] = 'padding: 10px; font-style: italic;'
|
||||||
|
|
||||||
|
|
|
@ -33,3 +33,8 @@
|
||||||
background-color: #685e79 !important;
|
background-color: #685e79 !important;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
details summary {
|
||||||
|
padding: 10px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
|
@ -32,3 +32,8 @@
|
||||||
background-color: #685e79 !important;
|
background-color: #685e79 !important;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
details summary {
|
||||||
|
padding: 10px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue