From 6e2c36bdbb1882b7029940291f661f4ecb8f88e2 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 29 Dec 2019 13:06:51 -0800 Subject: [PATCH] Restrict footnotes to appearing after good elements. Otherwise you can get blockquotes appearing inside inline elements which is invalid. --- cleanerupper/plugin.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cleanerupper/plugin.py b/cleanerupper/plugin.py index f3c8594..e10c1ee 100644 --- a/cleanerupper/plugin.py +++ b/cleanerupper/plugin.py @@ -123,15 +123,28 @@ def inject_footnotes(soup): 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].') continue + footnote_id = footnote_id.split('[', 1)[-1].split(']', 1)[0] if footnote_id not in global_footnotes: continue + footnote = global_footnotes[footnote_id] - footnote_link.parent.insert_after(footnote) + + + parent = footnote_link.parent + while parent and parent.name not in ['p', 'blockquote', 'div']: + parent = parent.parent + + if parent is None: + print(footnote_link, 'doesn\'t have a

or

ancestor.') + continue + + parent.insert_after(footnote) footnote_link.insert_before(footnote_link.contents[0]) footnote_link.decompose() remove_class(footnote, 'gcufootnote_content')