Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create links between paragraphs
  • Loading branch information
kthoden committed Apr 9, 2020
1 parent 3caa2eb commit 09ddd52
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/imxml2django.py
Expand Up @@ -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")

Expand Down

0 comments on commit 09ddd52

Please sign in to comment.