PluginBench
Skill
Pass
Audit score 90

mermaid-to-image

zc277584121/marketing-skills

Convert Mermaid diagram code blocks to PNG images using mermaid.ink API.

What is mermaid-to-image?

This skill finds Mermaid code blocks in Markdown or text files and renders them as PNG images via the mermaid.ink service, replacing the code blocks with image references. Use it when you need static images instead of Mermaid code for publishing platforms that don't natively support Mermaid diagrams.

  • Scans files for ```mermaid code blocks and counts them
  • Determines appropriate image output directory based on project structure
  • Renders each diagram to PNG using the mermaid.ink API with proper User-Agent headers
  • Generates descriptive filenames based on diagram content
  • Replaces code blocks with relative or absolute image references in Markdown
  • Handles multiple diagrams per file with unique filenames

How to install mermaid-to-image

npx skills add https://github.com/zc277584121/marketing-skills --skill mermaid-to-image
Prerequisites
  • Python with urllib and base64 modules (standard library)
  • Network access to mermaid.ink API
  • Target files containing ```mermaid code blocks
Claude Code
Cursor
Windsurf
Cline

How to use mermaid-to-image

  1. 1.Specify the target file(s) containing Mermaid blocks to convert
  2. 2.Allow the skill to scan and report how many blocks were found
  3. 3.Confirm or specify the image output directory (or select from suggested options)
  4. 4.The skill renders each diagram to PNG with descriptive filenames
  5. 5.Review the modified files where code blocks have been replaced with image references
  6. 6.Verify the generated images are in the correct output directory

Use cases

Good for
  • Converting Mermaid diagrams in documentation to static images for GitHub Pages or Jekyll sites
  • Preparing diagrams for publishing on platforms like Dev.to that don't render Mermaid natively
  • Batch converting architecture and flowchart diagrams in a docs folder to PNG format
  • Replacing Mermaid code blocks with images in README files for better compatibility
Who it's for
  • Technical writers publishing documentation to static site generators
  • Developers preparing content for platforms without Mermaid support
  • Teams standardizing on PNG diagrams for cross-platform compatibility
  • Documentation maintainers converting legacy Mermaid diagrams to images

mermaid-to-image FAQ

What if mermaid.ink times out on a large diagram?

The skill will report the error. You can simplify the diagram or try an alternative renderer. Very complex diagrams may exceed the API's processing limits.

How are image filenames chosen?

Filenames are based on diagram content (e.g., architecture-overview.png, data-flow.png) rather than generic names like mermaid-1.png, making them more meaningful.

Can this work with non-Markdown files?

Yes, the skill works with any text file containing Mermaid code blocks, including .rst, .txt, and other formats.

Should I use relative or absolute image paths?

Use relative paths by default. If the project uses absolute URLs (like GitHub Pages), match that style instead.

What if a file already has images for some diagrams?

The skill will report existing images and can skip them or ask for confirmation before processing.

Full instructions (SKILL.md)

Source of truth, from zc277584121/marketing-skills.


name: mermaid-to-image description: Convert Mermaid code blocks in Markdown files to PNG images using the mermaid.ink API.

Skill: Mermaid to Image

Convert ```mermaid code blocks in Markdown (or other text) files into PNG images, and replace the code blocks with image references. Useful for platforms that don't render Mermaid natively (GitHub Pages/Jekyll, Dev.to, etc.).


When to Use

  • The user asks to convert Mermaid diagrams in a file to images
  • The user wants to render specific Mermaid code blocks as PNG
  • A publishing workflow requires static images instead of Mermaid code blocks

Workflow

Step 1: Identify target files

The user may specify:

  • A single file: convert mermaid blocks in docs/architecture.md
  • Multiple files: convert mermaid in all files under docs/
  • A specific code block: convert the second mermaid block in README.md

Scan the target file(s) for ```mermaid code blocks. Report how many blocks were found and in which files before proceeding.

Step 2: Determine the image output directory

Check the project structure to find where images are typically stored:

# Look for common image directories
ls -d images/ img/ assets/ assets/images/ static/images/ docs/images/ 2>/dev/null

If a clear image directory exists (e.g., images/, assets/images/), use it. Create a subdirectory by topic if appropriate (e.g., images/<topic>/).

If no image directory is obvious or multiple candidates exist, ask the user:

Where should I save the rendered Mermaid images?

1. images/ (create new)
2. assets/images/
3. docs/figures/
4. Custom — enter a path

Step 3: Render each diagram to PNG

Use the mermaid.ink API to render diagrams. Run this Python snippet for each block:

import base64, urllib.request

def render_mermaid(code: str, output_path: str):
    """Render a Mermaid diagram to PNG via mermaid.ink API."""
    encoded = base64.urlsafe_b64encode(code.encode()).decode()
    url = f"https://mermaid.ink/img/{encoded}?bgColor=white"
    req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
    resp = urllib.request.urlopen(req, timeout=30)
    with open(output_path, "wb") as f:
        f.write(resp.read())

Important: The User-Agent header is required — mermaid.ink returns 403 without it.

Naming convention

Use descriptive filenames based on the diagram content, not generic names:

  • GOOD: architecture-overview.png, data-flow.png, heartbeat-sequence.png
  • BAD: mermaid-1.png, diagram.png, image1.png

Step 4: Replace code blocks with image references

Replace each ```mermaid ... ``` block with a Markdown image reference using a relative path from the file to the image:

![Architecture overview](images/topic/architecture-overview.png)

If the project uses absolute URLs (e.g., GitHub Pages), use those instead:

![Architecture overview](https://example.github.io/images/topic/architecture-overview.png)

Choose the link style that matches the project's existing image references. If unsure, use relative paths.

Step 5: Report results

After processing, summarize:

  • How many diagrams were converted
  • Where the images were saved
  • Which files were modified

Edge Cases

  • Large diagrams: mermaid.ink may time out on very complex diagrams. If a render fails, report the error and suggest the user simplify the diagram or try an alternative renderer.
  • Multiple blocks in one file: process all blocks in order, give each a unique descriptive filename.
  • Already-rendered blocks: if a mermaid block already has a corresponding image (commented out or adjacent), skip it or ask the user.
  • Non-Markdown files: the same approach works for any text file containing mermaid code blocks (e.g., .rst, .txt).