GuruDevvv/my-claude-skills / external/mermaid-tools
mermaid-tools
VerifiedExtracts Mermaid diagrams from markdown files and generates high-quality PNG images using bundled scripts. Activates when working with Mermaid diagrams, converting diagrams to PNG, extracting diagrams from markdown, or processing markdown files with embedded Mermaid code.
| File | Kind | Size |
|---|---|---|
| README.md | markdown | 1.4 KB |
| SKILL.md | skill md | 5.4 KB |
| references/setup_and_troubleshooting.md | markdown | 5.1 KB |
| scripts/extract-and-generate.sh | script | 5.2 KB |
| scripts/extract_diagrams.py | script | 4.9 KB |
| scripts/puppeteer-config.json | config | 356 B |
| КАК_ИСПОЛЬЗОВАТЬ.md | markdown | 512 B |
scripts/extract-and-generate.sh
View on GitHub#!/bin/bash
# Enhanced Mermaid diagram extraction and PNG generation script
# Extracts diagrams from markdown and numbers them sequentially
#
# Usage: ./extract-and-generate.sh <markdown_file> [output_directory]
# Example: ./extract-and-generate.sh <markdown_file> <output_directory>
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_FILE="$SCRIPT_DIR/puppeteer-config.json"
EXTRACTOR_SCRIPT="$SCRIPT_DIR/extract_diagrams.py"
# Parse arguments
if [ $# -lt 1 ]; then
echo "Usage: $0 <markdown_file> [output_directory]"
echo "Example: $0 <markdown_file> <output_directory>"
exit 1
fi
MARKDOWN_FILE="$1"
OUTPUT_DIR="${2:-$(dirname "$MARKDOWN_FILE")/diagrams}"
echo "=== Enhanced Mermaid Diagram Processor ==="
echo "Source markdown: $MARKDOWN_FILE"
echo "Output directory: $OUTPUT_DIR"
echo "Environment: WSL2 Ubuntu with Chrome dependencies"
echo
# Validate inputs
if [ ! -f "$MARKDOWN_FILE" ]; then
echo "ERROR: Markdown file not found: $MARKDOWN_FILE"
exit 1
fi
# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"
# Configuration
CHROME_PATH="/usr/bin/google-chrome-stable"
# Check dependencies
echo "Checking dependencies..."
if ! command -v mmdc &> /dev/null; then
echo "ERROR: @mermaid-js/mermaid-cli not installed"
echo "Install with: npm install -g @mermaid-js/mermaid-cli"
exit 1
fi
if [ ! -f "$CHROME_PATH" ]; then
# Не Linux/WSL (например, Windows): системного Chrome по этому пути нет.
# mermaid-cli умеет работать на своём встроенном браузере — просто не навязываем ему путь.
echo "NOTE: Chrome не найден по $CHROME_PATH — используем браузер, встроенный в mermaid-cli"
CHROME_PATH=""
fi
if [ ! -f "$CONFIG_FILE" ]; then
echo "ERROR: Puppeteer config not found: $CONFIG_FILE"
exit 1
fi
if [ ! -f "$EXTRACTOR_SCRIPT" ]; then
echo "ERROR: Python extractor script not found: $EXTRACTOR_SCRIPT"
exit 1
fi
echo "✅ Dependencies verified"
echo
# Extract Mermaid diagrams from markdown
echo "Extracting Mermaid diagrams from markdown..."
python3 "$EXTRACTOR_SCRIPT" "$MARKDOWN_FILE" "$OUTPUT_DIR"
if [ $? -ne 0 ]; then
echo "ERROR: Failed to extract diagrams from markdown"
exit 1
fi
echo
# Now generate PNGs using the existing generation logic
echo "Generating PNG files..."
cd "$OUTPUT_DIR"
# Default dimensions - can be overridden with environment variables
DEFAULT_WIDTH="${MERMAID_WIDTH:-1200}"
DEFAULT_HEIGHT="${MERMAID_HEIGHT:-800}"
SCALE_FACTOR="${MERMAID_SCALE:-2}"
# Process all .mmd files in order
mmd_files=(*.mmd)
if [ ${#mmd_files[@]} -eq 1 ] && [ "${mmd_files[0]}" = "*.mmd" ]; then
echo "No .mmd files found in output directory"
exit 0
fi
# Sort files numerically by their prefix
IFS=$'\n' mmd_files=($(sort -V <<< "${mmd_files[*]}"))
echo "Found ${#mmd_files[@]} Mermaid diagram(s) to process"
echo
for mmd_file in "${mmd_files[@]}"; do
if [ ! -f "$mmd_file" ]; then
continue
fi
# Extract filename without extension
diagram="${mmd_file%.mmd}"
# Use smart defaults based on diagram content or filename patterns
width="$DEFAULT_WIDTH"
height="$DEFAULT_HEIGHT"
# Smart sizing based on filename patterns
if [[ "$diagram" =~ timeline|gantt ]]; then
width=$((DEFAULT_WIDTH * 2)) # Wider for timelines
height=$((DEFAULT_HEIGHT / 2)) # Shorter for timelines
elif [[ "$diagram" =~ architecture|system ]]; then
width=$((DEFAULT_WIDTH * 2)) # Larger for complex diagrams
height=$((DEFAULT_HEIGHT * 2))
elif [[ "$diagram" =~ caching ]]; then
width=$((DEFAULT_WIDTH * 2)) # Larger for caching flowcharts
height=$((DEFAULT_HEIGHT * 2))
elif [[ "$diagram" =~ monitoring|workflow|sequence|api ]]; then
width=$((DEFAULT_WIDTH * 2)) # Wider for workflows and sequences
height="$DEFAULT_HEIGHT"
fi
echo "Generating $diagram.png (${width}x${height}, scale: ${SCALE_FACTOR}x)..."
if [ -n "$CHROME_PATH" ]; then
export PUPPETEER_EXECUTABLE_PATH="$CHROME_PATH"
else
unset PUPPETEER_EXECUTABLE_PATH
fi
mmdc \
-i "$mmd_file" \
-o "$diagram.png" \
--puppeteerConfigFile "$CONFIG_FILE" \
-w "$width" \
-H "$height" \
-s "$SCALE_FACTOR"
if [ $? -eq 0 ]; then
echo " ✅ Generated successfully"
else
echo " ❌ Generation failed"
continue
fi
# Validate PNG
if test -s "$diagram.png" && file "$diagram.png" | grep -q "PNG image"; then
size=$(stat -c%s "$diagram.png")
dimensions_actual=$(identify -format "%wx%h" "$diagram.png" 2>/dev/null || echo "unknown")
echo " ✅ Validated PNG (${size} bytes, ${dimensions_actual})"
else
echo " ❌ PNG validation failed"
fi
echo
done
echo "=== Generation Complete ==="
echo "All PNG diagrams generated and validated successfully!"
echo
echo "Generated files (in sequence order):"
ls -la [0-9][0-9]-*.png 2>/dev/null | awk '{printf " %s (%s bytes)\n", $9, $5}' || echo " No numbered PNG files found"
echo
echo "Generated files (all):"
ls -la *.png 2>/dev/null | awk '{printf " %s (%s bytes)\n", $9, $5}' || echo " No PNG files found"
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |