Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement EOAbox (grey infoboxes) for Django
  • Loading branch information
kthoden committed Sep 4, 2020
1 parent e571c4e commit a897d79
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
34 changes: 34 additions & 0 deletions src/eoatex2imxml.py
Expand Up @@ -1071,6 +1071,36 @@ def process_pararefs(xmlTree):
pararef.tag = "elementtobestripped"
# def process_pararefs ends here


def process_eoabox(xmlChapters):
"""Move contents of EOAbox into regular document structure
The EOAbox element is the child of a p tag and contains itself p
tags
"""

all_boxes = xmlTree.findall(".//EOAbox")
if len(all_boxes) == 0:
logging.info("Document contains no info boxes.")
else:
logging.info(f"Found {libeoaconvert.plural(len(all_boxes), 'box', plural='boxes')}.")

for box in all_boxes:
box_parent = box.getparent()
box_parent.tag = "elementtobestripped"
box_contents = list(box)
box_head = box_contents[0].find("head")
box_head.set("style", "boxhead")
box_head.tag = "p"
libeoaconvert.remove_wrapping_element(box_head.getparent())
for contents in box_contents[1:]:
contents.set("style", "box")

libeoaconvert.remove_wrapping_element(box)
libeoaconvert.remove_wrapping_element(box_parent)
return
# def process_eoabox ends here

def make_indices_child_of_div0():
"""Move index commands to a higher location"""

Expand Down Expand Up @@ -1374,6 +1404,10 @@ def add_bibliography_to_xml(
logging.info("Converting EOAchem")
process_eoachem( xmlChapters )

logging.info("-----------------------------------------------------")
logging.info("Converting EOAbox")
process_eoabox( xmlChapters )

logging.info("-----------------------------------------------------")
logging.info("EOAFigure Numbering per Chapter")
dictFigures = process_figures( xmlChapters )
Expand Down
33 changes: 9 additions & 24 deletions src/imxml2django.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8; mode: python -*-
# Time-stamp: <2020-09-02 13:33:37 (kthoden)>
# Time-stamp: <2020-09-04 19:15:08 (kthoden)>

"""
Create an XML file that can be inserted into the Django database
Expand Down Expand Up @@ -806,30 +806,15 @@ def djangoParseObject(xmlElement, indent=False, listtype=None, listnumber=0, uid
xmlResult.append(copied_line)
etree.strip_tags(xmlResult, "p")

elif xmlElement.tag == "EOAbox":
logging.debug("Found a box")
xmlResult = etree.Element("temp")
xmlResult.set("style", "box")

box_header = xmlElement.find("head")
box_header.tag = "EOAparagraph"
box_header.set("style", "box")
box_header.set("order", str(intObjectNumber))
head_contents = box_header.find("p")
head_contents.tag = "b"
# etree.strip_tags(box_header, "p")
xmlResult.append(box_header)
elif xmlElement.tag == "head" and xmlElement.get("style") == "boxhead":
xmlElement.tag = "b"
del xmlElement.attrib["style"]
wrapping_paragraph = etree.Element("EOAparagraph")
wrapping_paragraph.set("style", "box")
libeoaconvert.wrap_into_element(wrapping_paragraph, xmlElement)
wrapping_paragraph.set("order", str(intObjectNumber))
intObjectNumber += 1
# question: what to do about paragraph equivalent objects?
box_elements = xmlElement.getchildren()
logging.debug(len(box_elements))
for box_element in box_elements:
if box_element.tag == "p":
box_element.tag = "EOAparagraph"
box_element.set("style", "box")
box_element.set("order", str(intObjectNumber))
xmlResult.append(box_element)
intObjectNumber += 1
xmlResult = wrapping_paragraph
elif xmlElement.tag == "p" and xmlElement.get("class") == "divider":
xmlElement.tag = "EOAparagraph"
xmlElement.set("order", str(intObjectNumber))
Expand Down

0 comments on commit a897d79

Please sign in to comment.