Skip to content

Commit

Permalink
Nondashed full citation in popup
Browse files Browse the repository at this point in the history
  • Loading branch information
kthoden committed Dec 17, 2019
1 parent ba81382 commit fb2739c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 14 deletions.
69 changes: 57 additions & 12 deletions src/eoatex2imxml.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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!
""" <a class="publications-popup-text" data-title="Halliday and
Resnick 1977, 232" data-content="Physics">Halliday and Resnick
1977, 232</a>"""
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
Expand Down
6 changes: 4 additions & 2 deletions src/utils/libeoaconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
"&" : "&amp;",
"<" : "&lt;" ,
">" : "&gt;",
"'" : "&apos;",
"&" : "&amp;",
'"' : "&quot;",
}

Expand Down

0 comments on commit fb2739c

Please sign in to comment.