Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_replace_citations_strings_with_ids():
"""
Test that text does not get converted to:
> our new Manubot tool [@cTN2TQIL-rootstock; @cTN2TQIL] for automating
manuscript generation.
See https://github.com/greenelab/manubot/issues/9
"""
string_to_id = {
'@url:https://github.com/greenelab/manubot': 'cTN2TQIL',
'@url:https://github.com/greenelab/manubot-rootstock': '1B7Y2HVtw',
}
text = 'our new Manubot tool [@url:https://github.com/greenelab/manubot-rootstock; @url:https://github.com/greenelab/manubot] for automating manuscript generation.'
text = replace_citations_strings_with_ids(text, string_to_id)
assert '[@1B7Y2HVtw; @cTN2TQIL]' in text
def prepare_manuscript(args):
"""
Compile manuscript, creating manuscript.md and references.json as inputs
for pandoc.
"""
text = get_text(args.content_directory)
citation_df = get_citation_df(args, text)
generate_csl_items(args, citation_df)
citation_string_to_id = collections.OrderedDict(
zip(citation_df.string, citation_df.citation_id))
text = replace_citations_strings_with_ids(text, citation_string_to_id)
metadata, variables = get_metadata_and_variables(args)
variables['manuscript_stats'] = get_manuscript_stats(text, citation_df)
with args.variables_path.open('w') as write_file:
json.dump(variables, write_file, indent=2)
write_file.write('\n')
text = template_with_jinja2(text, variables)
# Write manuscript for pandoc
with args.manuscript_path.open('w') as write_file:
yaml.dump(metadata, write_file, default_flow_style=False,
explicit_start=True, explicit_end=True)
write_file.write('\n')
write_file.write(text)