From fb2739cd4b39d073e687f446cb4dfc499662e0d6 Mon Sep 17 00:00:00 2001 From: kthoden Date: Tue, 17 Dec 2019 15:41:05 +0100 Subject: [PATCH] Nondashed full citation in popup --- src/eoatex2imxml.py | 69 +++++++++++++++++++++++++++++++------- src/utils/libeoaconvert.py | 6 ++-- 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/src/eoatex2imxml.py b/src/eoatex2imxml.py index f596957..ce8584e 100755 --- a/src/eoatex2imxml.py +++ b/src/eoatex2imxml.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8; mode: python -*- -# Time-stamp: <2019-11-26 12:35:10 (kthoden)> +# Time-stamp: <2019-12-17 13:07:39 (kthoden)> """ Converts Latex files into a customized DocBook XML file. @@ -106,6 +106,16 @@ "-t", "--trash", help="Remove temporary files." ) +parser.add_argument( + "-n", "--no-bib4ht", + action="store_true", + help="Skip creation of bibliography, rely on already present HTML files." +) +parser.add_argument( + "-classic", "--eoa-classic", + action="store_true", + help="Embed webdesign of EOA1.0 into XML" +) args = parser.parse_args() @@ -381,6 +391,17 @@ def cleanup(): logging.info("No temporary files were found.") # def cleanup ends here + +def reduce_element_tag(xml_element): + """Remove attributes from root and make root a one letter tag""" + + xml_element.tag = "t" + xml_element.attrib.clear() + + return xml_element +# def reduce_element_tag ends here + + # Remove temporary files, neccessary for troubleshooting if args.trash == "temp": cleanup() @@ -1378,6 +1399,8 @@ def add_bibliography_to_xml( if bibl_info is None: logging.warning("No bibliography database found.") +elif args.no_bib4ht: + logging.warning("Proceeding without typesetting bibligraphy.") else: (bib_type, bib_database) = bibl_info logging.debug(f"bib type is {bib_type}") @@ -1518,6 +1541,8 @@ def add_bibliography_to_xml( # [1:-1] to remove parentheses around citations try: citeauthoryear_value = form_cit.select("#citeauthoryear ~ p > span[data-cites='%s']" % string_citekey)[0].text + strTitle = form_cit.select("#citefull ~ p[data-cites='%s']" % string_citekey)[0].text + # strTitle_element = form_cit.select("#citefull ~ p[data-cites='%s']" % string_citekey)[0] # citeauthoryear_value = form_cit.select("#citeauthoryear ~ p > span[data-cites='%s']" % string_citekey)[0].text[1:-1] except IndexError: logging.error("Could not find {}. Exiting.".format(string_citekey)) @@ -1554,22 +1579,42 @@ def add_bibliography_to_xml( # Hier den XML-Tag durch die Quellenangabe ersetzen tmpTail = xmlCitation.tail xmlCitation.clear() - xmlCitation.tag = "span" - xmlCitation.set("rel", "popover") - xmlCitation.set("class", "citation") - xmlCitation.set("citekey", string_citekey) - xmlCitation.text = strCitation - xmlCitation.tail = tmpTail - # Create Link to be used for website in a popover - xmlCitation.set("data-toggle", "popover") - xmlCitation.set("html", "true") - xmlCitation.set("data-placement", "bottom") - xmlCitation.set("data-title", data_title_value) + + if args.eoa_classic: + xmlCitation.tag = "span" + xmlCitation.set("rel", "popover") + xmlCitation.set("class", "citation") + # Create Link to be used for website in a popover + xmlCitation.set("data-toggle", "popover") + xmlCitation.set("html", "true") + xmlCitation.set("data-placement", "bottom") + else: + # this is taken from tei2imxml! + """ Halliday and Resnick + 1977, 232""" + xmlCitation.tag = "a" + xmlCitation.set("class", "publications-popup-text") + + # citation.set("data-content", cited_data[citekey][2]) + # citation.text = sanitized_citation_string + # end of taken from imxml + + # str_title_element = reduce_element_tag(etree.fromstring(str(strTitle_element))) + # element_string = etree.tostring(str_title_element) + # strTitle = libeoaconvert.escape_xml(element_string[3:-4]) + try: xmlCitation.set("data-content", strTitle) except: xmlCitation.set("data-content", "missing") + xmlCitation.text = strCitation + xmlCitation.tail = tmpTail + + xmlCitation.set("citekey", string_citekey) + xmlCitation.set("data-title", data_title_value) counter_citations += 1 + intChapterNumber += 1 # If Bibliography-Type is monograph-numeric search for EOAbibliography and make it all diff --git a/src/utils/libeoaconvert.py b/src/utils/libeoaconvert.py index 8fcf512..2bd1be5 100644 --- a/src/utils/libeoaconvert.py +++ b/src/utils/libeoaconvert.py @@ -466,14 +466,16 @@ def restore_xml_tags(text): # def restore_xml_tags ends here -def escape_xml(text): +def escape_xml(text_bytes): """Convert xml markup to entities""" + text = text_bytes.decode("utf-8") + replacements = { + "&" : "&", "<" : "<" , ">" : ">", "'" : "'", - "&" : "&", '"' : """, }