Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _exit_without_pandoc():
"""
Given info from get_pandoc_info, exit Python if Pandoc is not available.
"""
info = get_pandoc_info()
for command in "pandoc", "pandoc-citeproc":
if not info[command]:
logging.critical(
f'"{command}" not found on system. ' f"Check that Pandoc is installed."
)
raise SystemExit(1)
def call_pandoc(metadata, path, format="plain"):
"""
path is the path to write to.
"""
_exit_without_pandoc()
info = get_pandoc_info()
_check_pandoc_version(info, metadata, format)
metadata_block = "---\n{yaml}\n...\n".format(
yaml=json.dumps(metadata, ensure_ascii=False, indent=2)
)
args = [
"pandoc",
"--filter",
"pandoc-citeproc",
"--output",
str(path) if path else "-",
]
if format == "markdown":
args.extend(["--to", "markdown_strict", "--wrap", "none"])
elif format == "jats":
args.extend(["--to", "jats", "--standalone"])
elif format == "docx":
Text representation of the bibligriophy, such as a JSON-formatted string.
`input_format` should be specified if providing text input.
input_format : str or None
Manually specified input formatted that is supported by pandoc-citeproc:
https://github.com/jgm/pandoc-citeproc/blob/master/man/pandoc-citeproc.1.md#options
Returns
-------
csl_json : JSON-like object
CSL JSON Data for the references encoded by the input bibliography.
"""
use_text = path is None
use_path = text is None
if not (use_text ^ use_path):
raise ValueError("load_bibliography: specify either path or text but not both.")
if not get_pandoc_info()["pandoc-citeproc"]:
logging.error(
"pandoc-citeproc not found on system: manubot.pandoc.bibliography.load_bibliography returning empty CSL JSON"
)
return []
args = ["pandoc-citeproc", "--bib2json"]
if input_format:
args.extend(["--format", input_format])
run_kwargs = {}
if use_path:
args.append(str(path))
if use_text:
run_kwargs["input"] = text
logging.info("call_pandoc subprocess args:\n>>> " + shlex_join(args))
process = subprocess.run(
args,
stdout=subprocess.PIPE,