Handle nested footnotes in separate passes.

Otherwise the nested one lands where the parent one already is,
then doesn't get moved to the real destination.
This commit is contained in:
Ethan Dalool 2019-12-29 13:05:28 -08:00
parent 5195b3a560
commit d89394215b

View file

@ -115,8 +115,13 @@ def collect_footnotes(soup):
def inject_footnotes(soup): def inject_footnotes(soup):
footnote_links = soup.find_all('span', {'class': 'gcufootnote_link'}) footnote_links = soup.find_all('span', {'class': 'gcufootnote_link'})
for footnote_link in reversed(footnote_links): for footnote_link in reversed(footnote_links):
if contains_class(footnote_link.parent, 'gcufootnote_content'):
# In the case of nested footnotes, let's place the parent first
# and come back for this child on the next go around.
continue
if len(footnote_link.contents) != 1: if len(footnote_link.contents) != 1:
print(footnote_link, 'is malformed. Should just be >[id<.') print(footnote_link, 'is malformed. Should just be >[id]<.')
footnote_id = footnote_link.contents[0] footnote_id = footnote_link.contents[0]
if not footnote_id.startswith('['): if not footnote_id.startswith('['):
print(footnote_link, 'is malformed. Should start with [id].') print(footnote_link, 'is malformed. Should start with [id].')