The pypandoc package is incredible
I've been doing a lot of Markdown-to-Microsoft Word work lately, and while I have used and loved Pandoc for a long time, the biggest issue is usually getting the Pandoc binary installed on whatever target environment in which my code is running.
Today I just discovered the incredible pypandoc package, which not only provides a clean and simple wrapper for interacting with Pandoc, but which also includes the pandoc
binary in the package. With a simple pip install pypandoc-binary
, I can now directly interact with Pandoc from my Python code.
Here's an example of how easy it is to get a Python string of Markdown content (report_markdown
) written to a Microsoft Word document that is based on an existing template document (at the path template_file_path
):
pypandoc.convert_text(
source=report_markdown,
format="md",
outputfile="pypandoc_exploration.docx",
to="docx",
extra_args=[f"--reference-doc={template_file_path}"],
)