Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Chapter formatting and cleanup
  • Loading branch information
Klaus Thoden committed May 29, 2018
1 parent 3e07e8c commit 60bee92
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions tei2imxml.py
Expand Up @@ -618,17 +618,20 @@ def assign_ids(xml_tree, data):
sections = chapter.findall(".//div2") sections = chapter.findall(".//div2")
section_counter = 1 section_counter = 1
for section in sections: for section in sections:
section_number = "%d.%d" % (chapter_counter, section_counter)
section.set("id-text", section_number)
secdict[section.get("id")] = section_number


subsection_counter = 1 if section.get('rend') != "nonumber":
subsections = section.findall(".//div3") section_number = "%d.%d" % (chapter_counter, section_counter)
section.set("id-text", section_number)
secdict[section.get("id")] = section_number

subsection_counter = 1
subsections = section.findall(".//div3")
for subsection in subsections: for subsection in subsections:
subsection_number = "%d.%d.%d" % (chapter_counter, section_counter, subsection_counter) if subsection.get('rend') != "nonumber":
subsection.set("id-text", subsection_number) subsection_number = "%d.%d.%d" % (chapter_counter, section_counter, subsection_counter)
secdict[subsection.get("id")] = subsection_number subsection.set("id-text", subsection_number)
subsection_counter += 1 secdict[subsection.get("id")] = subsection_number
subsection_counter += 1


section_counter += 1 section_counter += 1
chapter_counter += 1 chapter_counter += 1
Expand Down Expand Up @@ -899,7 +902,10 @@ def fix_bib_entries(div_snippet):
element_counter += 1 element_counter += 1


assigned_ids, data_to_pickle = assign_ids(resulting_tree, data) assigned_ids, data_to_pickle = assign_ids(resulting_tree, data)
xml_root = assigned_ids.getroot()
updated_xml_tree = update_ids(assigned_ids)

xml_root = updated_xml_tree.getroot()


xml_root.tag = "Book" xml_root.tag = "Book"


Expand Down Expand Up @@ -931,7 +937,7 @@ def fix_bib_entries(div_snippet):
logging.info("Wrote %s." % output_filename) logging.info("Wrote %s." % output_filename)


# Remove namespace info (brute force solution) # Remove namespace info (brute force solution)
bad_ns_string = 'xmlns="http://www.tei-c.org/ns/1.0"' bad_ns_string = ' xmlns="http://www.tei-c.org/ns/1.0"'
with open(output_filename, 'r') as textfile: with open(output_filename, 'r') as textfile:
xml_as_string = textfile.read() xml_as_string = textfile.read()


Expand Down

0 comments on commit 60bee92

Please sign in to comment.