From c2248a8def0ed29b75ef5ed4d347b29bfb2ebd20 Mon Sep 17 00:00:00 2001 From: Montana Rowe Date: Tue, 22 Mar 2016 09:32:27 -0500 Subject: [PATCH] Refuse to mix old-style and new-style footnotes within a chapter, and use old-style footnotes' fragments for backwards compatibility of footnote URLs. --- Skripten/EOAconvert.py | 54 +++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/Skripten/EOAconvert.py b/Skripten/EOAconvert.py index 43deda6..70d8027 100755 --- a/Skripten/EOAconvert.py +++ b/Skripten/EOAconvert.py @@ -823,12 +823,6 @@ def get_bigfoot_data(chapter): ] -bigfoot_data = [ - get_bigfoot_data(xmlChapter) - for xmlChapter - in xmlChapters -] - print ("-----------------------------------------------------") print ("Numbering of Lists per Chapter") for xmlChapter in xmlChapters: @@ -1556,17 +1550,30 @@ def bring_footnote_down_epub(footnote, footnote_name, destination): return contentopf +class FootnoteError(Exception): + pass + for xmlChapter in xmlChapters: groupings = get_bigfoot_data(xmlChapter) - xmlFootnotes = xmlChapter.findall(".//note") - if len(xmlFootnotes) == 0: - if not len([note for grouping, notes in groupings for note in notes]): + xmlFootnotes = list(xmlChapter.findall(".//note")) + has_old = 0 != len(xmlFootnotes) + has_new = 0 != len( + [ + note + for grouping, notes in groupings + for note in notes + ] + ) + if has_old: + if has_new: + raise FootnoteError("This chapter contains both old-style footnotes and new-style footnotes") + else: + if not has_new: continue xmlNewFootnotes = etree.Element("div") xmlNewFootnotesHeader = etree.Element("h3") xmlNewFootnotesHeader.text = dictLangFootnotes[xmlChapter.get("language")] xmlNewFootnotes.append(xmlNewFootnotesHeader) - notes_so_far = 0 for grouping, notes in groupings: for index, note in enumerate(notes): footnote_name = str(index + 1) @@ -1576,8 +1583,7 @@ def bring_footnote_down_epub(footnote, footnote_name, destination): para.text = "[%s] %s" % (footnote_name, note.text) contentopf = bring_footnote_down_epub(note, footnote_name, para) xmlNewFootnotes.append(para) - notes_so_far += len(notes) - intFootnoteNumber = notes_so_far + 1 + intFootnoteNumber = 1 for xmlFootnote in xmlFootnotes: # Not numbered Equations may appear in a footnote, need to be treated differently xmlEquationsnonumber = xmlFootnote.findall(".//EOAequationnonumber") @@ -2824,9 +2830,21 @@ def bring_footnote_down_django(footnote, fragment, footnote_number, object_numbe xmlEOAchapters = xmlEOAdocument.findall(".//EOAchapter") -for chapter_index, (xmlEOAchapter, groupings) in enumerate(zip(xmlEOAchapters, bigfoot_data)): - if len(xmlEOAchapter.findall(".//note")) == 0: - if not len([note for grouping, notes in groupings for note in notes]): +for xmlEOAchapter in xmlEOAchapters: + groupings = get_bigfoot_data(xmlEOAchapter) + has_old = 0 != len(xmlEOAchapter.findall(".//note")) + has_new = 0 != len( + [ + note + for grouping, notes in groupings + for note in notes + ] + ) + if has_old: + if has_new: + raise FootnoteError("This chapter contains both old-style footnotes and new-style footnotes") + else: + if not has_new: continue # Find out running order of last item the chapter # Hier pro FN zunächst die EOAequationnonumber in

korrigieren @@ -2845,17 +2863,15 @@ def bring_footnote_down_django(footnote, fragment, footnote_number, object_numbe xmlEOAsection.append(xmlHead) xmlResult.append(xmlEOAsection) - notes_so_far = 0 for grouping, notes in groupings: for index, note in enumerate(notes): - unique_id = "bfn_%s_%s_%s" % (chapter_index, grouping, index) fntext = str(index+1) if "lower-latin" == grouping: fntext = alph_fndex(index) + unique_id = "fn%s" % fntext intObjectNumber = bring_footnote_down_django(note, unique_id, fntext, intObjectNumber, unique_id, xmlResult) - notes_so_far += len(notes) - intFootnoteNumber = notes_so_far + 1 + intFootnoteNumber = 1 xmlFootnotes = xmlEOAchapter.findall(".//note") for xmlFootnote in xmlFootnotes: xmlFootnoteContent = xmlFootnote.getchildren()