Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refuse to mix old-style and new-style footnotes within a chapter, and…
… use old-style footnotes' fragments for backwards compatibility of footnote URLs.
  • Loading branch information
calcnerd256 committed Mar 22, 2016
1 parent 7e7968e commit c2248a8
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions Skripten/EOAconvert.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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 <p> korrigieren
Expand All @@ -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()
Expand Down

0 comments on commit c2248a8

Please sign in to comment.