A tool for converting Mermaid diagrams in Markdown to high-res PNG images
Project description
MermaidPix
Why MermaidPix?
In the world of technical documentation and diagramming, Mermaid has become an invaluable tool for creating clear, version-controllable diagrams using simple text-based syntax. However, sharing these diagrams outside of Markdown-rendering environments or in high-resolution formats can be challenging.
MermaidPix bridges this gap by automatically converting Mermaid diagrams in your Markdown files into high-resolution PNG images. This tool ensures that your diagrams are:
- Easily shareable in any context.
- Rendered in high quality for presentations or publications.
- Consistently generated, allowing for version control of both the diagram code and the resulting image.
What is MermaidPix?
MermaidPix is a Python-based command-line tool that:
- Scans Markdown files for Mermaid diagram code blocks.
- Converts each Mermaid diagram to a high-resolution PNG image.
- Replaces the Mermaid code in the Markdown with a link to the generated image.
- Maintains idempotency by generating consistent filenames based on diagram content.
Key Features
- High-resolution output (4K) with transparent backgrounds.
- Deterministic file naming for easy version control.
- Efficient processing with caching of previously generated images.
- Verbose logging option for detailed conversion information.
How to Use MermaidPix
Prerequisites
- Python 3.7 or higher.
- pipx (for installing Python applications globally).
- Poetry (for dependency management and packaging).
- Mermaid CLI (mmdc).
Installation
Step 1: Install pipx
If you haven't installed pipx yet, you can do so using pip:
pip install --user pipx
pipx ensurepath
Install using Pypi:
pipx install mermaidpix
Step 2: Install Poetry
Use pipx to install Poetry:
pipx install poetry
Step 3: Install Mermaid CLI
Install Mermaid CLI globally using npm:
npm install -g @mermaid-js/mermaid-cli
Step 4: Install MermaidPix
Clone the repository and install MermaidPix using Poetry:
git clone https://github.com/raphaelmansuy/mermaidpix.git
cd mermaidpix
poetry install
This will create a virtual environment and install all the necessary dependencies.
Usage
To use MermaidPix, you can run it directly through Poetry:
poetry run python mermaid_pix/main.py <input_file> <output_file> [-v]
Alternatively, you can activate the Poetry shell and run the script:
poetry shell
python mermaid_pix/main.py <input_file> <output_file> [-v]
Command Line Arguments
<input_file>: Path to the input Markdown file.<output_file>: Path where the processed Markdown file will be saved.-vor--verbose: (Optional) Enable verbose logging.
Example
poetry run python mermaid_pix/main.py docs/architecture.md docs/architecture_with_images.md -v
This command will:
- Read
docs/architecture.md. - Convert any Mermaid diagrams to PNGs and save them in the same directory as the output file.
- Create a new file
docs/architecture_with_images.mdwith image links replacing Mermaid code blocks. - Provide verbose output of the conversion process.
Example Input and Output
Input Markdown (input.md):
# System Architecture
Here's our current system architecture:
graph TD
A[Client] -->|HTTP Request| B(Load Balancer)
B -->|Forward| C{Web Server}
C -->|Query| D[(Database)]
C -->|Cache| E((Redis))
This diagram shows the basic flow of our system.
After running MermaidPix:
poetry run python mermaid_pix/main.py input.md output.md
Output Markdown (output.md):
# System Architecture
Here's our current system architecture:

This diagram shows the basic flow of our system.
The Mermaid diagram is now converted to a high-resolution PNG image, making it easily viewable in any Markdown reader or web browser.
Development
To set up MermaidPix for development:
-
Clone the repository:
git clone https://github.com/yourusername/mermaidpix.git cd mermaidpix
-
Install dependencies:
poetry install -
Activate the virtual environment:
poetry shell -
Make your changes and run tests:
poetry run pytest
Contributing
We welcome contributions to MermaidPix! Please see our CONTRIBUTING.md for details on how to submit pull requests, report issues, or request features.
License
MermaidPix is released under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mermaidpix-0.7.3.tar.gz.
File metadata
- Download URL: mermaidpix-0.7.3.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/24.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54deb8c4a6e54c27a19683750a910f0b66faa300b2f89fa49513e2e65a852fab
|
|
| MD5 |
52d590371f602c1e3e8cbe256f42c6b2
|
|
| BLAKE2b-256 |
290818fce1550667df037a5e4c21037a5709774ba8715a7ea12a9e1d3a56d81d
|
File details
Details for the file mermaidpix-0.7.3-py3-none-any.whl.
File metadata
- Download URL: mermaidpix-0.7.3-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/24.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70557a34e55c6ffddbfa388168b28d518f0d1ccd1f231e93e15baa0c2d7a995e
|
|
| MD5 |
21f006e553737ca4650fc367ae627515
|
|
| BLAKE2b-256 |
abf86f073c9412940d42dc23fc20104be1f0b3654bcb7e9fae3321b2598dce95
|