- main_xml_part = part_xml[0] # było [0][0], master
- nav_map = toc_file[-1] # było [-1][-1]
- depth = 1 # navmap
-
- if len(input_xml.getroot()) > 1:
- # rdf before style master
- main_text = input_xml.getroot()[1]
- else:
- # rdf in style master
- main_text = input_xml.getroot()[0]
-
- replace_characters(main_text)
- zip.writestr('OPS/title.html',
- etree.tostring(xslt(input_xml, res('xsltTitle.xsl')), pretty_print=True))
-
- # Search for table of contents elements and book division
-
- stupid_i = stupid_j = stupid_k = 1
- last_node_part = False
- for one_part in main_text:
- name = one_part.tag
- if name in ("naglowek_czesc", "naglowek_rozdzial", "naglowek_akt", "srodtytul"):
- if name == "naglowek_czesc":
- stupid_k = 1
- last_node_part = True
- find_annotations(annotations, part_xml, stupid_j)
- replace_by_verse(part_xml)
- zip.writestr('OPS/part%d.html' % stupid_j,
- etree.tostring(xslt(part_xml, res('xsltScheme.xsl')), pretty_print=True))
- main_xml_part[:] = [deepcopy(one_part)]
- # add to manifest and spine
- add_to_manifest(manifest, stupid_j)
- add_to_spine(spine, stupid_j)
- name_toc = node_name(one_part)
- # build table of contents
- # i+2 because of title page
- add_nav_point(nav_map, stupid_i+2, name_toc, stupid_j + 1)
- stupid_i += 1
- stupid_j += 1
- else:
- if last_node_part:
- main_xml_part.append(one_part)
- last_node_part = False
- name_toc = node_name(one_part)
- add_nav_point(nav_map, stupid_i + 1, name_toc, stupid_j)
- else:
- stupid_k = 1
- find_annotations(annotations, part_xml, stupid_j)
- replace_by_verse(part_xml)
- zip.writestr('OPS/part%d.html' % stupid_j,
- etree.tostring(xslt(part_xml, res('xsltScheme.xsl')), pretty_print=True))
- # start building a new part
- main_xml_part[:] = [deepcopy(one_part)]
- add_to_manifest(manifest, stupid_j)
- add_to_spine(spine, stupid_j)
- name_toc = node_name(one_part)
- add_nav_point(nav_map, stupid_i + 2, name_toc, stupid_j + 1) # title page
- stupid_j += 1
- stupid_i += 1
- else:
- if name in ('naglowek_podrozdzial', 'naglowek_scena'):
- depth = 2
- name_toc = node_name(one_part)
- add_nav_point2(nav_map, stupid_i + 2, name_toc, stupid_j, stupid_k)
- one_part.set('sub', str(stupid_k))
- stupid_k += 1
- stupid_i += 1
- main_xml_part.append(deepcopy(one_part))
- last_node_part = False
- find_annotations(annotations, part_xml, stupid_j)
- replace_by_verse(part_xml)
- add_to_manifest(manifest, stupid_j)
- add_to_spine(spine, stupid_j)