From d89394215b0ff36818c83a5b1f664048136af238 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 29 Dec 2019 13:05:28 -0800 Subject: [PATCH] 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. --- cleanerupper/plugin.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cleanerupper/plugin.py b/cleanerupper/plugin.py index 1a765a4..f3c8594 100644 --- a/cleanerupper/plugin.py +++ b/cleanerupper/plugin.py @@ -115,8 +115,13 @@ def collect_footnotes(soup): def inject_footnotes(soup): footnote_links = soup.find_all('span', {'class': 'gcufootnote_link'}) 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: - print(footnote_link, 'is malformed. Should just be >[id<.') + print(footnote_link, 'is malformed. Should just be >[id]<.') + footnote_id = footnote_link.contents[0] if not footnote_id.startswith('['): print(footnote_link, 'is malformed. Should start with [id].')