npx skills add ...
npx skills add zc277584121/marketing-skills --skill mermaid-to-image
Convert Mermaid code blocks in Markdown files to PNG images using the mermaid.ink API.
npx skills add zc277584121/marketing-skills --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.).
The user may specify:
convert mermaid blocks in docs/architecture.mdconvert mermaid in all files under docs/convert the second mermaid block in README.mdScan the target file(s) for ```mermaid code blocks. Report how many blocks were found and in which files before proceeding.
Check the project structure to find where images are typically stored:
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:
Use the mermaid.ink API to render diagrams. Run this Python snippet for each block:
Important: The User-Agent header is required — mermaid.ink returns 403 without it.
Use descriptive filenames based on the diagram content, not generic names:
architecture-overview.png, data-flow.png, heartbeat-sequence.pngmermaid-1.png, diagram.png, image1.pngReplace each ```mermaid ... ``` block with a Markdown image reference using a relative path from the file to the image:
If the project uses absolute URLs (e.g., GitHub Pages), use those instead:
Choose the link style that matches the project's existing image references. If unsure, use relative paths.
After processing, summarize:
.rst, .txt).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())