diff --git a/src/imxml2django.py b/src/imxml2django.py index 979d881..e1ec4ba 100755 --- a/src/imxml2django.py +++ b/src/imxml2django.py @@ -1868,6 +1868,34 @@ def bring_footnote_down_django(footnote, fragment, footnote_number, object_numbe xmlEOAindex.tag = "temp" logging.debug("Found index in footnote") +logging.info("----------------------------------------------") +logging.info("Creating paragraph links") + +paragraphs_with_corresp = xmlDjangoTree.xpath("//EOAparagraph[@corresp]") +for pc in paragraphs_with_corresp: + # get order of target and the chapter order to create the + # hyperlink pick this up on publicationimport and extend the model + # for a field, probably containing the html snippet for the URL + corresponding_attribute = pc.get("corresp")[1:] + corresponding_paragraph = xmlDjangoTree.xpath("//EOAparagraph[@xml:id='{}']".format(corresponding_attribute)) + if len(corresponding_paragraph) == 0: + logging.error("There seems to be no corresponding xml:id for %s. Exiting." % corresponding_attribute) + sys.exit(1) + elif len(corresponding_paragraph) > 1: + logging.error("The xml:id %s has been assigned more than once. This is not allowed. Exiting." % corresponding_paragraph[0].attrib["{http://www.w3.org/XML/1998/namespace}id"]) + sys.exit(1) + else: + eoa_id_element = corresponding_paragraph[0] + paragraph_order = eoa_id_element.get("order") + for xml_parent in eoa_id_element.iterancestors(): + if xml_parent.tag == "EOAchapter": + chapter_order = xml_parent.get("order") + href_text = f"../{chapter_order}/index.html#{paragraph_order}" + pc.set("href", href_text) + +for pc in paragraphs_with_corresp: + etree.strip_attributes(pc, "corresp", "{http://www.w3.org/XML/1998/namespace}id") + logging.info("----------------------------------------------") logging.info("Sorting and Creating Regular Index")