How to use the manubot.pandoc.util.get_pandoc_info function in manubot

To help you get started, we’ve selected a few manubot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github manubot / manubot / manubot / cite / cite_command.py View on Github external
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)
github manubot / manubot / manubot / cite / cite_command.py View on Github external
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":
github manubot / manubot / manubot / pandoc / bibliography.py View on Github external
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,