diff --git a/src/imxml2django.py b/src/imxml2django.py index 046d740..8bdd37d 100755 --- a/src/imxml2django.py +++ b/src/imxml2django.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8; mode: python -*- -# Time-stamp: <2020-09-07 10:28:32 (kthoden)> +# Time-stamp: <2020-09-11 16:38:19 (kthoden)> """ Create an XML file that can be inserted into the Django database @@ -1039,6 +1039,56 @@ def treat_verselines(verse_element): return xml_result # def treat_verselines ends here +def bring_footnote_down_django(footnote, fragment, footnote_number, object_number, unique_id, destination): + """ + captures reusable behavior from the existing code + potentially, some of the old code could be replaced by calls to this helper + + usage: intObjectNumber = bring_footnote_down_django(xmlFootnote, "fn"+str(intFootnoteNumber), str(intFootnoteNumber), intObjectNumber, tmpStrUID, xmlResult) + unfortunately, returning the result seemed like a better idea than mutating the global variable + """ + + kids = list(footnote.getchildren()) + footnote_text = footnote.text or "" + replace_footnote_with_sup(footnote) + footnote.set("class", "footnote") + anchor = etree.Element("a") + anchor.set("href", "#" + fragment) # "fn" + str(intFootnoteNumber) + anchor.text = footnote_number # str(intFootnoteNumber) + footnote.append(anchor) + foot = etree.Element("EOAfootnote") + foot.set("order", str(object_number)) + object_number += 1 + foot.set("number", footnote_number) + anchor_number = next( + iter( + ( + parent.get("order") + for parent + in footnote.iterancestors() + if parent.get("order") is not None + ) + ) + ) + foot.set("anchor", anchor_number) + foot.set("id", unique_id) + foot.text = footnote_text + for kid in kids: + if "EOAequationnonumber" == kid.tag: + cwd = os.getcwd() + shutil.copy( + "%s/items/%s" % (cwd, kid.get("filename")), + "%s/images/" % cwd, + ) + foot.append(kid) + destination.append(foot) + + return object_number +# def bring_footnote_down_django ends here + +############################### +# End of function definitions # +############################### # Iterate over Chapters, Sections, Subsections, and Subsubsections and # Put all on one level: EOAchapter @@ -1260,56 +1310,9 @@ def treat_verselines(verse_element): logging.info("----------------------------------------------") logging.info("Processing and linking Footnotes for django") -def bring_footnote_down_django(footnote, fragment, footnote_number, object_number, unique_id, destination): - """ - captures reusable behavior from the existing code - potentially, some of the old code could be replaced by calls to this helper - - usage: intObjectNumber = bring_footnote_down_django(xmlFootnote, "fn"+str(intFootnoteNumber), str(intFootnoteNumber), intObjectNumber, tmpStrUID, xmlResult) - unfortunately, returning the result seemed like a better idea than mutating the global variable - """ - - kids = list(footnote.getchildren()) - footnote_text = footnote.text or "" - replace_footnote_with_sup(footnote) - footnote.set("class", "footnote") - anchor = etree.Element("a") - anchor.set("href", "#" + fragment) # "fn" + str(intFootnoteNumber) - anchor.text = footnote_number # str(intFootnoteNumber) - footnote.append(anchor) - foot = etree.Element("EOAfootnote") - foot.set("order", str(object_number)) - object_number += 1 - foot.set("number", footnote_number) - anchor_number = next( - iter( - ( - parent.get("order") - for parent - in footnote.iterancestors() - if parent.get("order") is not None - ) - ) - ) - foot.set("anchor", anchor_number) - foot.set("id", unique_id) - foot.text = footnote_text - for kid in kids: - if "EOAequationnonumber" == kid.tag: - cwd = os.getcwd() - shutil.copy( - "%s/items/%s" % (cwd, kid.get("filename")), - "%s/images/" % cwd, - ) - foot.append(kid) - destination.append(foot) - - return object_number -# def bring_footnote_down_django ends here - xmlEOAchapters = xmlEOAdocument.findall(".//EOAchapter") -debug_chapters(xmlEOAchapters) +# debug_chapters(xmlEOAchapters) translation_xml = etree.parse( str( TRANSLATION_FILE ) ) dictLangFootnotes = translation_xml.find("//entry[@name='footnotes']").attrib