Skip to content

Commit 07b81ee

Browse files
Merge pull request #72 from oreillymedia/dev021124_2
Adjust logic for selecting top-level sections
2 parents 995868a + 72dd3cf commit 07b81ee

File tree

3 files changed

+467
-3
lines changed

3 files changed

+467
-3
lines changed

jupyter_book_to_htmlbook/file_processing.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,15 @@ def get_top_level_sections(soup):
141141
all but bibliography sections
142142
"""
143143
section_wrappers = soup.find_all("article", attrs={"role": "main"})
144+
top_level_sections = []
144145

145146
# test case for partial files, not expected in production
146147
if len(section_wrappers) == 0:
147148
sections = soup.find_all('section')
149+
150+
for section in sections:
151+
if section.find_parent('section') is None:
152+
top_level_sections.append(section)
148153
elif len(section_wrappers) != 1:
149154
article = soup.find('article', attrs={"role": "main"})
150155
try:
@@ -156,16 +161,15 @@ def get_top_level_sections(soup):
156161
return None, None
157162
else:
158163
main = section_wrappers[0]
159-
sections = []
160164

161165
for element in main.children:
162166
if (
163167
element.name == "section" and
164168
element.get('id') != "bibliography"
165169
):
166-
sections.append(element)
170+
top_level_sections.append(element)
167171

168-
return sections
172+
return top_level_sections
169173

170174

171175
def get_main_section(soup):

0 commit comments

Comments
 (0)