Skip to content

Commit

Permalink
tei->imxml: get rid of dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
EsGeh authored and EsGeh committed Dec 18, 2019
1 parent dee98be commit 513d929
Showing 1 changed file with 3 additions and 78 deletions.
81 changes: 3 additions & 78 deletions src/tei2imxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,36 +316,6 @@ def format_reference_list(used_citekeys, html_file):
return references
# def format_reference_list ends here

def format_citations_json(used_citekeys, bibdata, html_file):
"""Return a dictionary of the used citations as formatted entries.
citation_dict[citekey] = (authoryear_citation, year_citation, title)
"""

with open(html_file, "r") as ding:
cites = BeautifulSoup(ding, "html.parser")

citation_dict = {}

for entry in used_citekeys:
for entry_2 in bibdata:
if entry_2["id"] == entry:
current_citation = entry
logging.debug(f"""{html_file}: {entry}.""")
try:
strTitle = entry_2["title"]
except KeyError:
logging.warning("No title found for %s", entry)

title = strTitle
authoryear_citation = cites.select("#citeauthoryear ~ p > span[data-cites='%s']" % entry)[0].text
year_citation = cites.select("#citeyear ~ p > span[data-cites='%s']" % entry)[0].text
citation_dict[entry] = (authoryear_citation, year_citation, title)

return citation_dict
# def format_citations_json ends here


def format_citations(used_citekeys, bibdata, html_file):
"""Return a dictionary of the used citations as formatted entries.
Expand Down Expand Up @@ -1252,28 +1222,8 @@ def get_citations_per_chapter(xml_tree):
return refs_per_chapter
# def get_citations_per_chapter ends here

def convert_bibliography_to_json(bib_data, TEMP_DIR):
"""Create a JSON version of bibliography data, using pandoc-citeproc"""

interim_bib_json_file = Path(TEMP_DIR) / "tmp-bib.json"
citeproc_command = "pandoc-citeproc --bib2json %s" % bib_data["source"]
citeproc_arguments = shlex.split(citeproc_command)
citeproc_process = subprocess.Popen(citeproc_arguments, stdout=subprocess.PIPE)
citeproc_json = citeproc_process.stdout.read()
citations_json = json.loads(citeproc_json)

with open(interim_bib_json_file, 'w') as json_file:
json_file.write(citeproc_json.decode('utf-8'))

logging.info(f"Wrote bibliography as interim json file: {interim_bib_json_file}.")

return citations_json
# def convert_bibliography_to_json ends here


def convert_bibliography_to_dict(
bib_data,
input_dir,
bib_file : Path
):
"""Create a dictionary from bibliography data."""

Expand All @@ -1283,34 +1233,13 @@ def convert_bibliography_to_dict(

bibliography_dict = {}

with open(Path( input_dir / bib_data["source"])) as btf:
with open(bib_file) as btf:
btb = bibtexparser.load(btf, parser=parser)
bibliography_dict = btb.entries_dict

return bibliography_dict
# def convert_bibliography_to_dict ends here


def make_bibliography_pandoc(used_citekeys, bib_data, citations_json, output_file_root, CSL_FILE):
"""Create the HTML version of the bibliography using pandoc
Return the filename of HTML file.
"""

citations_filename_html = Path(output_file_root).with_suffix(".html")
citations_filename_markdown = Path(output_file_root).with_suffix(".md")
write_citation_markdown(used_citekeys, citations_filename_markdown)
markdown_command = "pandoc -o %s -t html --filter=pandoc-citeproc --bibliography=%s --csl=%s %s" % (citations_filename_html, bib_data["source"], CSL_FILE, citations_filename_markdown)
arguments = shlex.split(markdown_command)
logging.info("Using external command pandoc: %s." % markdown_command)
subprocess.call(arguments)
logging.info("Finished processing the bibtex file.")
logging.info(f"Wrote {citations_filename_html}.")

return citations_filename_html
# def make_bibliography_pandoc ends here


def make_bibliography_tex4ht(
used_citekeys,
bib_data,
Expand Down Expand Up @@ -1564,17 +1493,14 @@ def main():

bib_data = check_bibliography(xml_tree)

# citations_json = convert_bibliography_to_json(bib_data, TEMP_DIR)
citations_dict = convert_bibliography_to_dict(
bib_data,
INPUT_DIR
INPUT_DIR / bib_data["source"]
)

logging.debug("Creating bibliographies.")
if bib_data["type"] == "monograph":
used_citekeys = get_all_citations(xml_tree)
citations_filename_root = Path(TEMP_DIR, "formatted_citations_monograph")
# citations_filename_html = make_bibliography_pandoc(used_citekeys, bib_data, citations_json, citations_filename_root, CSL_FILE)

if args.no_bib4ht:
citations_filename_html = citations_filename_root.with_suffix(".html")
Expand Down Expand Up @@ -1607,7 +1533,6 @@ def main():
continue
else:
citations_filename_root = Path(TEMP_DIR, f"formatted_citations_{chapter_id}")
# citations_filename_html_per_chapter = make_bibliography_pandoc(used_citekeys_per_chapter, bib_data, citations_json, citations_filename_root, CSL_FILE)
if args.no_bib4ht:
citations_filename_html_per_chapter = citations_filename_root.with_suffix(".html")
logging.info("Skipping creation of HTML bibliography files. Using the existing ones.")
Expand Down

0 comments on commit 513d929

Please sign in to comment.