Skip to content

πŸ”„ Convert Mermaid diagram files (.mmd) to high-resolution PNG images with optimized settings. This Python utility provides batch processing capabilities, customizable scaling, and transparent backgrounds, making it perfect for documentation and diagram management workflows.

Notifications You must be signed in to change notification settings

doomL/mermaid-bulk-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Mermaid Diagram Converter

A Python utility that converts Mermaid diagram files to high-resolution PNG images with optimized settings and transparent backgrounds.

Features

  • Batch conversion of .mmd files to PNG format
  • High-resolution output with customizable scaling
  • Transparent background support
  • Optimized diagram settings for better readability
  • Configurable font sizes and spacing
  • Error handling and detailed logging

Prerequisites

  • Python 3.6 or higher
  • Node.js and npm installed

Installation

  1. Clone this repository:
git clone https://github.com/doomL/mermaid-bulk-converter
cd mermaid-bulk-converter
  1. Install Python dependencies:
pip install pathlib
  1. Install Mermaid CLI:

Method 1: Local Installation (Recommended)

npm install -g @mermaid-js/mermaid-cli

Usage

Run the script from the command line:

python mermaid-bulk-converter.py -i /path/to/input/directory -o /path/to/output/directory -s 3.0

Arguments

  • -i, --input: Directory containing Mermaid (.mmd) files
  • -o, --output: Directory where PNG files will be saved
  • -s, --scale: Scale factor for PNG resolution (default: 3.0)

Example

  1. Create a Mermaid diagram file flowchart.mmd:
graph TD
    A[Start] --> B{Decision}
    B -->|Yes| C[OK]
    B -->|No| D[Cancel]
Loading
  1. Convert to PNG:
python mermaid-bulk-converter.py -i ./diagrams -o ./output -s 4.0

Configuration

The script uses optimized default settings for:

  • Font size and family
  • Diagram padding and spacing
  • Node layout and dimensions
  • Background transparency
  • Device scale factor

These settings can be modified in the config dictionary within the script.

Error Handling

The script includes comprehensive error handling:

  • Creates missing output directories
  • Reports conversion errors for individual files
  • Cleans up temporary files
  • Provides detailed error messages

License

MIT License

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

About

πŸ”„ Convert Mermaid diagram files (.mmd) to high-resolution PNG images with optimized settings. This Python utility provides batch processing capabilities, customizable scaling, and transparent backgrounds, making it perfect for documentation and diagram management workflows.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages