,

Integrating pandoc-mermaid-filter with Pandoc and Docker

Lake Davenberg Avatar

·

Integrating pandoc-mermaid-filter with Pandoc and Docker

Documentation is an essential part of any software project, and including diagrams can greatly enhance the understanding of complex concepts. Mermaid is a popular JavaScript-based diagramming tool that allows you to create diagrams using simple text code. However, when working with large documentation projects, manually converting mermaid code blocks to images can be time-consuming. That’s where pandoc-mermaid-filter comes in. This Python-based filter seamlessly integrates with the Pandoc document converter, automatically converting mermaid code blocks to mermaid images.

Installation

To get started, you first need to install pandoc-mermaid-filter using pip:

#bash
pip install pandoc-mermaid-filter

Usage with Pandoc

Once installed, you can use pandoc-mermaid-filter like any other Pandoc filter. Simply specify it as the filter when converting your Markdown document to the desired output format. For example, to convert a Markdown document (sample.md) containing mermaid code blocks to a PDF document, run the following command:

#bash
pandoc sample.md -o sample.pdf --filter pandoc-mermaid

Make sure that the mermaid binary is in your $PATH or set the MERMAID_BIN environment variable to the location of the binary.

Usage with Docker

If you prefer, you can also use Docker to run pandoc-mermaid-filter. Docker provides a consistent and reproducible environment for running applications, making it easy to include pandoc-mermaid-filter in your documentation workflow.

To use pandoc-mermaid-filter with Docker, first, create a Dockerfile in your project directory with the following content:

#dockerfile
FROM pandoc/latex:latest

RUN apt-get update && \
    apt-get install -y mermaid-cli && \
    pip install pandoc-mermaid-filter

CMD [ "pandoc" ]

This Dockerfile uses the official pandoc/latex image as the base image, installs the mermaid-cli package, and then installs pandoc-mermaid-filter using pip. It also sets the default command to pandoc, allowing you to run Pandoc commands directly in the Docker container.

Build the Docker image using the following command:

#bash
docker build -t my-pandoc .

Once the image is built, you can use it to convert your Markdown document (sample.md) to a PDF document by running the following command:

#bash
docker run --rm -v ${PWD}:/documents my-pandoc sample.md -o sample.pdf --filter pandoc-mermaid

This command mounts your current working directory (${PWD}) as a volume in the Docker container, allowing the container to access your Markdown document. The converted PDF document will be saved in your current working directory.

Advantages of Integrating pandoc-mermaid-filter

  1. Seamless Conversion: Integrating pandoc-mermaid-filter with Pandoc or Docker allows for seamless conversion of mermaid code blocks to mermaid images in your documentation. You no longer need to manually convert each code block, saving you time and effort.
  2. Consistent Formatting: The filter ensures that all mermaid code blocks are converted to high-quality, consistent images. This improves the visual appeal and readability of your documentation, making it easier for readers to understand complex concepts.
  3. Integration Flexibility: By integrating with Pandoc or Docker, pandoc-mermaid-filter can be easily incorporated into existing documentation workflows. Whether you prefer using Pandoc for document conversion or Docker for containerized environments, you have the flexibility to choose the integration method that works best for your needs.

In conclusion, integrating pandoc-mermaid-filter with Pandoc and Docker provides a powerful solution for converting mermaid code blocks to mermaid images in your documentation. This integration saves time, ensures consistent formatting, and offers flexibility, making it an innovative market catalyst in Cloud Ecosystems for documentation.

Try out pandoc-mermaid-filter today and take your documentation to the next level!

Resources

Leave a Reply

Your email address will not be published. Required fields are marked *