Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some additional changes
  • Loading branch information
Klaus Thoden committed Mar 7, 2018
1 parent 8a5092e commit e2b1b6c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tei2django.py
Expand Up @@ -13,7 +13,7 @@
import mkimage

OUTPUT_DIR = "./CONVERT"
XSL_FILE = "./data/tei2django.xsl"
XSL_FILE = os.path.dirname(sys.argv[0]) + "/data/tei2django.xsl"
FIGURE_DIR = "./data/images"

def process_formulas(xml_tree):
Expand Down
28 changes: 19 additions & 9 deletions transform_xml.py
Expand Up @@ -295,7 +295,7 @@ def transform_body(xml_tree, cited_data, publang):
hi.tag = "EOAdown"
del hi.attrib["rend"]
else:
logging.debug("The rend attribute in hi has the value %s. This is not supported" % rend_attribute)
logging.info("The rend attribute in hi has the value %s. This is not supported" % rend_attribute)

return xml_tree
# def transform_body ends here
Expand Down Expand Up @@ -429,11 +429,6 @@ def add_bibliography(xml_tree, refs_for_bib_chapter):
bib_data["source"] = xml_tree.xpath("//t:teiHeader/t:fileDesc/t:sourceDesc/t:listBibl/@source", namespaces=NS_MAP)[0]
bib_data["type"] = xml_tree.xpath("//t:teiHeader/t:fileDesc/t:sourceDesc/t:listBibl/@type", namespaces=NS_MAP)[0]

command = "pandoc -o %sformatted_citations.html -t html --filter=pandoc-citeproc --bibliography=%s --csl=%s %s" % (OUTPUT_DIR + os.path.sep, bib_data["source"], CSL_FILE, OUTPUT_DIR + os.path.sep + "used_citations.md")
arguments = shlex.split(command)
logging.info("Using external command pandoc.")
subprocess.call(arguments)

# json
interim_bib_json_file = "tmp-bib.json"
citeproc_command = "pandoc-citeproc --bib2json %s" % bib_data["source"]
Expand All @@ -442,12 +437,18 @@ def add_bibliography(xml_tree, refs_for_bib_chapter):
citeproc_json = citeproc_process.stdout.read()
citations_json = json.loads(citeproc_json)

if bib_data["type"] not in ["monograph", "anthology", "monograph-numeric", "anthology-numeric"]:
print("The bibliography type %s is not allowed." % bib_data["type"])

command = "pandoc -o %sformatted_citations.html -t html --filter=pandoc-citeproc --bibliography=%s --csl=%s %s" % (OUTPUT_DIR + os.path.sep, bib_data["source"], CSL_FILE, OUTPUT_DIR + os.path.sep + "used_citations.md")
arguments = shlex.split(command)
logging.info("Using external command pandoc.")
subprocess.call(arguments)

# refs for bib_chapter contains formatted reference entries
cited_dict, refs_for_bib_chapter = format_citations(set(used_citekeys), citations_json)
# render_reference(all_references, cited_dict)

assert(bib_data["type"] in ["monograph", "anthology", "monograph-numeric", "anthology-numeric"])

tei_body = xml_tree.xpath("//t:text", namespaces=NS_MAP)[0]

body_transformed = transform_body(tei_body, cited_dict, publang=publication_language)
Expand Down Expand Up @@ -487,5 +488,14 @@ def add_bibliography(xml_tree, refs_for_bib_chapter):

# resulting_tree.write(output_filename, pretty_print=True, xml_declaration=True,encoding="utf-8")
final_tree.write(output_filename, pretty_print=True, xml_declaration=True,encoding="utf-8")
logging.debug("Wrote %s." % output_filename)
logging.info("Wrote %s." % output_filename)

bad_ns_string = 'xmlns="http://www.tei-c.org/ns/1.0"'
with open(output_filename, 'r') as textfile:
xml_as_string = textfile.read()

removed_namespace = xml_as_string.replace(bad_ns_string, "")

with open(output_filename, 'w') as amended_textfile:
amended_textfile.write(removed_namespace)
# finis

0 comments on commit e2b1b6c

Please sign in to comment.