Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/juanma-wp/block-mermaid-diagram/archive/refs/heads/main.zipA WordPress block plugin that enables you to create beautiful diagrams and flowcharts using Mermaid syntax directly in your WordPress posts and pages.
Description
The JuanMa Mermaid Diagram Block integrates the powerful Mermaid.js library into WordPress, allowing you to create various types of diagrams using simple text-based syntax. Perfect for documentation, tutorials, technical blogs, and any content that benefits from visual representations.
The MVP of this block was created using Telex, showcasing how quickly powerful WordPress blocks can be built with AI assistance. Read about the development process in this blog post: Playing with Telex: Building a Mermaid Diagram Block in Just a Few Prompts.
Features
- Live Preview: See your diagrams render in real-time as you type in the block editor
- Multiple Diagram Types: Support for flowcharts, sequence diagrams, class diagrams, state diagrams, and more
- WordPress Interactivity API: Built using WordPress's modern Interactivity API for optimal performance
- Optimized Loading: Mermaid.js library loads only when the block is present on the page
- Block Alignment: Support for various alignment options (left, center, right, wide, full)
Installation
- Download the plugin or clone this repository
- Place it in your WordPress
/wp-content/plugins/directory - Run
npm installto install dependencies - Run
npm run buildto build the block assets - Activate the plugin through the WordPress admin panel
Development
Prerequisites
- Node.js (v14 or higher)
- npm or yarn
- WordPress development environment
Setup
# Install dependencies
npm install
# Start development server
npm run start
# Build for production
npm run build
Local Development Environment
The plugin includes wp-env for local development:
# Start local WordPress environment
npm run env:start
# Stop the environment
npm run env:stop
# Access the environment bash
npm run env:bash
# Clean and reset environment
npm run env:reset
Available Scripts
npm run build- Build the block for productionnpm run start- Start development mode with hot reloadnpm run lint:js- Lint JavaScript filesnpm run lint:css- Lint CSS filesnpm run format- Format code using WordPress coding standardsnpm run plugin-zip- Create a plugin zip file for distribution
Usage
- Add a new block in the WordPress editor
- Search for "Mermaid Diagram"
- Insert the block
- Write your Mermaid syntax in the editor
- The diagram will render automatically
Example Mermaid Syntax
graph TD
A[Start] --> B{Is it working?}
B -->|Yes| C[Great!]
B -->|No| D[Fix it]
D --> B
Supported Diagram Types
- Flowcharts
- Sequence Diagrams
- Class Diagrams
- State Diagrams
- Entity Relationship Diagrams
- Gantt Charts
- Pie Charts
- Git Graphs
- User Journey Maps
For complete Mermaid syntax documentation, visit Mermaid.js Documentation.
Requirements
- WordPress 6.1 or higher
- PHP 7.0 or higher
License
This plugin is licensed under GPLv2 or later. See the LICENSE file for details.
Author
JuanMa Garrido Email: juanma.garrido@gmail.com
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues, questions, or feature requests, please open an issue on the GitHub repository.