drafael/coding-harness / skills/pretty-mermaid
pretty-mermaid
VerifiedRender beautiful Mermaid diagrams as SVG or ASCII art using the beautiful-mermaid library. Supports 15+ themes, 5 diagram types (flowchart, sequence, state, class, ER), and ultra-fast rendering. Use this skill when: 1. User asks to "render a mermaid diagram" or provides .mmd files 2. User requests "create a flowchart/sequence diagram/state diagram" 3. User wants to "apply a theme" or "beautify a diagram" 4. User needs to "batch process multiple diagrams" 5. User mentions "ASCII diagram" or "terminal-friendly diagram" 6. User wants to visualize architecture, workflows, or data models
| File | Kind | Size |
|---|---|---|
| .gitignore | other | 122 B |
| LICENSE | other | 1.1 KB |
| README.md | markdown | 911 B |
| SKILL.md | skill md | 10.7 KB |
| assets/example_diagrams/class.mmd | other | 515 B |
| assets/example_diagrams/er.mmd | other | 584 B |
| assets/example_diagrams/flowchart.mmd | other | 253 B |
| assets/example_diagrams/sequence.mmd | other | 295 B |
| assets/example_diagrams/state.mmd | other | 225 B |
| package-lock.json | manifest | 1.5 KB |
| package.json | manifest | 313 B |
| references/DIAGRAM_TYPES.md | markdown | 6.2 KB |
| references/THEMES.md | markdown | 8.9 KB |
| references/api_reference.md | markdown | 968 B |
| scripts/batch.mjs | script | 5.4 KB |
| scripts/render.mjs | script | 5.3 KB |
| scripts/themes.mjs | script | 1.6 KB |
scripts/batch.mjs
View on GitHub#!/usr/bin/env node
import { execSync } from 'child_process';
import { dirname, join, resolve } from 'path';
import { fileURLToPath } from 'url';
import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync } from 'fs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const skillRoot = join(__dirname, '..');
async function loadBeautifulMermaid() {
try {
return await import('beautiful-mermaid');
} catch {}
console.error('[beautiful-mermaid] Dependency not found. Installing automatically...');
try {
execSync('npm install --no-fund --no-audit', {
cwd: skillRoot,
stdio: ['pipe', 'pipe', 'inherit'],
timeout: 120000,
});
console.error('[beautiful-mermaid] Installed successfully.\n');
} catch (e) {
console.error(`[beautiful-mermaid] Auto-install failed: ${e.message}`);
console.error(`Manual fix: cd ${skillRoot} && npm install`);
process.exit(1);
}
try {
const pkgPath = join(skillRoot, 'node_modules', 'beautiful-mermaid', 'dist', 'index.js');
return await import(pkgPath);
} catch (e) {
console.error(`[beautiful-mermaid] Failed to load after install: ${e.message}`);
process.exit(1);
}
}
function parseArgs() {
const args = process.argv.slice(2);
const opts = {
inputDir: null,
outputDir: null,
format: 'svg',
theme: null,
bg: null,
fg: null,
transparent: false,
useAscii: false,
workers: 4,
};
for (let i = 0; i < args.length; i++) {
const key = args[i];
const val = args[i + 1];
switch (key) {
case '--input-dir': case '-i': opts.inputDir = val; i++; break;
case '--output-dir': case '-o': opts.outputDir = val; i++; break;
case '--format': case '-f': opts.format = val; i++; break;
case '--theme': case '-t': opts.theme = val; i++; break;
case '--bg': opts.bg = val; i++; break;
case '--fg': opts.fg = val; i++; break;
case '--transparent': opts.transparent = true; break;
case '--use-ascii': opts.useAscii = true; break;
case '--workers': case '-w': opts.workers = parseInt(val); i++; break;
case '--help': case '-h':
console.log(`Usage: node batch.mjs --input-dir <dir> --output-dir <dir> [options]
Options:
-i, --input-dir <dir> Input directory containing .mmd files [required]
-o, --output-dir <dir> Output directory for rendered files [required]
-f, --format <fmt> Output format: svg | ascii (default: svg)
-t, --theme <name> Theme name (e.g. tokyo-night, dracula)
--bg <hex> Background color
--fg <hex> Foreground color
--transparent Transparent background (SVG only)
--use-ascii Pure ASCII instead of Unicode (ASCII only)
-w, --workers <n> Parallel workers (default: 4)`);
process.exit(0);
}
}
if (!opts.inputDir) {
console.error('Error: --input-dir is required. Use --help for usage.');
process.exit(1);
}
if (!opts.outputDir) {
console.error('Error: --output-dir is required. Use --help for usage.');
process.exit(1);
}
if (!existsSync(opts.inputDir)) {
console.error(`Error: Input directory not found: ${opts.inputDir}`);
process.exit(1);
}
return opts;
}
async function renderFile(file, inputDir, outputDir, opts, lib) {
const { renderMermaid, renderMermaidAscii, THEMES } = lib;
const inputPath = join(inputDir, file);
const ext = opts.format === 'svg' ? '.svg' : '.txt';
const outputPath = join(outputDir, file.replace(/\.mmd$/, ext));
const input = readFileSync(inputPath, 'utf8');
if (opts.format === 'ascii') {
const ascii = renderMermaidAscii(input, { useAscii: opts.useAscii });
writeFileSync(outputPath, ascii);
} else {
const theme = opts.theme ? THEMES[opts.theme] : undefined;
const colors = theme || {
...(opts.bg && { bg: opts.bg }),
...(opts.fg && { fg: opts.fg }),
};
const svg = await renderMermaid(input, {
...colors,
transparent: opts.transparent,
});
writeFileSync(outputPath, svg);
}
}
async function main() {
const opts = parseArgs();
const lib = await loadBeautifulMermaid();
mkdirSync(opts.outputDir, { recursive: true });
const files = readdirSync(opts.inputDir).filter(f => f.endsWith('.mmd'));
if (files.length === 0) {
console.error(`No .mmd files found in ${opts.inputDir}`);
process.exit(1);
}
console.log(`Found ${files.length} diagram(s) to render...`);
let success = 0;
const failed = [];
// Process in batches of `workers` size
for (let i = 0; i < files.length; i += opts.workers) {
const batch = files.slice(i, i + opts.workers);
const results = await Promise.allSettled(
batch.map(file => renderFile(file, opts.inputDir, opts.outputDir, opts, lib))
);
results.forEach((result, idx) => {
const file = batch[idx];
if (result.status === 'fulfilled') {
console.log(`\u2713 ${file}`);
success++;
} else {
console.error(`\u2717 ${file}: ${result.reason?.message || result.reason}`);
failed.push([file, result.reason?.message || String(result.reason)]);
}
});
}
console.log(`\n${success}/${files.length} diagrams rendered successfully`);
if (failed.length > 0) {
console.error(`\n${failed.length} failed:`);
for (const [file, error] of failed) {
console.error(` - ${file}: ${error}`);
}
process.exit(1);
}
}
main().catch(e => {
console.error('Error:', e.message);
process.exit(1);
});
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 470k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |