AI Agent Skill to generate and render beautiful Mermaid diagrams as SVG or terminal ASCII — 15 themes, 6 diagram types, batch CLI, no browser.
JavaScript agent-skillsai-agentsascii-artclaude-codecodexcursordiagram-generatordocumentationflowchartmermaidmermaid-diagramskillssvg
fix: align CLI themes with renderer options
imxva004897f260b
diff --git a/SKILL.md b/SKILL.mdindex 4c0c042..0e4c4b0 100644--- a/SKILL.md+++ b/SKILL.md@@ -154,7 +154,6 @@ node scripts/render.mjs \--input chart.mmd \--node-spacing 32 \--layer-spacing 56 \- --thoroughness 5 \--interactive \--output chart.svg```diff --git a/references/api_reference.md b/references/api_reference.mdindex 5fe3757..70a5a8d 100644--- a/references/api_reference.md+++ b/references/api_reference.md@@ -34,7 +34,6 @@ Legacy aliases `renderMermaid` and `renderMermaidAscii` still exist in 1.1.3, bu| `nodeSpacing` | `24` | Horizontal spacing between sibling nodes || `layerSpacing` | `40` | Vertical spacing between layers || `componentSpacing` | `24` | Spacing between disconnected components |-| `thoroughness` | `3` | Crossing-minimization trials from 1 to 7 || `interactive` | `false` | Hover tooltips for XY chart bars and points |## ASCII Optionsdiff --git a/scripts/batch.mjs b/scripts/batch.mjsindex ec14769..1cdc0a1 100644--- a/scripts/batch.mjs+++ b/scripts/batch.mjs@@ -8,6 +8,21 @@ import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync } fromconst __dirname = dirname(fileURLToPath(import.meta.url));const skillRoot = join(__dirname, '..');+function toAsciiTheme(colors) {+ if (!colors) return undefined;++ return {+ fg: colors.fg,+ border: colors.border ?? colors.fg,+ line: colors.line ?? colors.fg,+ arrow: colors.accent ?? colors.line ?? colors.fg,+ accent: colors.accent ?? colors.fg,+ bg: colors.bg,+ corner: colors.border ?? colors.line ?? colors.fg,+ junction: colors.accent ?? colors.border ?? colors.line ?? colors.fg,+ };+}+async function loadBeautifulMermaid() {try {return await import('beautiful-mermaid');@@ -61,7 +76,6 @@ function parseArgs() {nodeSpacing: 24,layerSpacing: 40,componentSpacing: 24,- thoroughness: 3,interactive: false,workers: 4,};@@ -93,7 +107,6 @@ function parseArgs() {case '--node-spacing': opts.nodeSpacing = parseInt(val); i++; break;case '--layer-spacing': opts.layerSpacing = parseInt(val); i++; break;case '--component-spacing': opts.componentSpacing = parseInt(val); i++; break;- case '--thoroughness': opts.thoroughness = parseInt(val); i++; break;case '--interactive': opts.interactive = true; break;case '--workers': case '-w': opts.workers = parseInt(val); i++; break;case '--help': case '-h':@@ -122,7 +135,6 @@ Options:--node-spacing <n> SVG horizontal node spacing (default: 24)--layer-spacing <n> SVG vertical layer spacing (default: 40)--component-spacing <n> SVG disconnected component spacing (default: 24)- --thoroughness <n> SVG layout trials, 1-7 (default: 3)--interactive Enable XY chart hover tooltips (SVG only)-w, --workers <n> Parallel workers (default: 4)`);process.exit(0);@@ -151,6 +163,7 @@ async function renderFile(file, inputDir, outputDir, opts, lib) {const ext = opts.format === 'svg' ? '.svg' : '.txt';const outputPath = join(outputDir, file.replace(/\.mmd$/, ext));const input = readFileSync(inputPath, 'utf8');+ const theme = opts.theme ? THEMES[opts.theme] : undefined;if (opts.format === 'ascii') {const ascii = renderMermaidASCII(input, {@@ -159,10 +172,10 @@ async function renderFile(file, inputDir, outputDir, opts, lib) {paddingY: opts.paddingY,boxBorderPadding: opts.boxBorderPadding,colorMode: opts.colorMode,+ theme: toAsciiTheme(theme),});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 }),@@ -181,7 +194,6 @@ async function renderFile(file, inputDir, outputDir, opts, lib) {nodeSpacing: opts.nodeSpacing,layerSpacing: opts.layerSpacing,componentSpacing: opts.componentSpacing,- thoroughness: opts.thoroughness,interactive: opts.interactive,});writeFileSync(outputPath, svg);diff --git a/scripts/render.mjs b/scripts/render.mjsindex 91d7813..cc67bb2 100644--- a/scripts/render.mjs+++ b/scripts/render.mjs@@ -8,6 +8,21 @@ import { readFileSync, writeFileSync, existsSync } from 'fs';const __dirname = dirname(fileURLToPath(import.meta.url));const skillRoot = join(__dirname, '..');+function toAsciiTheme(colors) {+ if (!colors) return undefined;++ return {+ fg: colors.fg,+ border: colors.border ?? colors.fg,+ line: colors.line ?? colors.fg,+ arrow: colors.accent ?? colors.line ?? colors.fg,+ accent: colors.accent ?? colors.fg,+ bg: colors.bg,+ corner: colors.border ?? colors.line ?? colors.fg,+ junction: colors.accent ?? colors.border ?? colors.line ?? colors.fg,+ };+}+async function loadBeautifulMermaid() {try {return await import('beautiful-mermaid');@@ -56,7 +71,6 @@ function parseArgs() {nodeSpacing: 24,layerSpacing: 40,componentSpacing: 24,- thoroughness: 3,interactive: false,};@@ -87,7 +101,6 @@ function parseArgs() {case '--node-spacing': opts.nodeSpacing = parseInt(val); i++; break;case '--layer-spacing': opts.layerSpacing = parseInt(val); i++; break;case '--component-spacing': opts.componentSpacing = parseInt(val); i++; break;- case '--thoroughness': opts.thoroughness = parseInt(val); i++; break;case '--interactive': opts.interactive = true; break;case '--help': case '-h':console.log(`Usage: node render.mjs --input <file> [options]@@ -115,7 +128,6 @@ Options:--node-spacing <n> SVG horizontal node spacing (default: 24)--layer-spacing <n> SVG vertical layer spacing (default: 40)--component-spacing <n> SVG disconnected component spacing (default: 24)- --thoroughness <n> SVG layout trials, 1-7 (default: 3)--interactive Enable XY chart hover tooltips (SVG only)`);process.exit(0);}@@ -142,6 +154,7 @@ async function main() {if (opts.theme && !Object.prototype.hasOwnProperty.call(THEMES, opts.theme)) {throw new Error(`Unknown theme: ${opts.theme}. Run node scripts/themes.mjs to list themes.`);}+ const theme = opts.theme ? THEMES[opts.theme] : undefined;if (opts.format === 'ascii') {const ascii = renderMermaidASCII(input, {@@ -150,6 +163,7 @@ async function main() {paddingY: opts.paddingY,boxBorderPadding: opts.boxBorderPadding,colorMode: opts.colorMode,+ theme: toAsciiTheme(theme),});if (opts.output) {writeFileSync(opts.output, ascii);@@ -158,7 +172,6 @@ async function main() {console.log(ascii);}} else {- const theme = opts.theme ? THEMES[opts.theme] : undefined;const colors = theme || {bg: opts.bg,fg: opts.fg,@@ -177,7 +190,6 @@ async function main() {nodeSpacing: opts.nodeSpacing,layerSpacing: opts.layerSpacing,componentSpacing: opts.componentSpacing,- thoroughness: opts.thoroughness,interactive: opts.interactive,});diff --git a/scripts/smoke-test.mjs b/scripts/smoke-test.mjsindex 84e5239..a0c58b7 100644--- a/scripts/smoke-test.mjs+++ b/scripts/smoke-test.mjs@@ -31,6 +31,7 @@ for (const file of files) {const cliTestDir = mkdtempSync(join(tmpdir(), 'pretty-mermaid-smoke-'));const flowchartPath = join(examplesDir, 'flowchart.mmd');+const xychartPath = join(examplesDir, 'xychart.mmd');try {for (const themeName of inheritedThemeNames) {@@ -51,8 +52,56 @@ try {assert.notEqual(batchResult.status, 0, `batch.mjs accepted inherited theme: ${themeName}`);assert.match(batchResult.stderr, /Unknown theme:/);}++ const interactiveSvgPath = join(cliTestDir, 'interactive.svg');+ const renderInteractiveResult = spawnSync(process.execPath, [+ join(scriptsDir, 'render.mjs'),+ '--input', xychartPath,+ '--output', interactiveSvgPath,+ '--interactive',+ ], { encoding: 'utf8' });+ assert.equal(renderInteractiveResult.status, 0, renderInteractiveResult.stderr);+ assert.match(readFileSync(interactiveSvgPath, 'utf8'), /class="xychart-tip/);++ const batchInteractiveDir = join(cliTestDir, 'batch-interactive');+ const batchInteractiveResult = spawnSync(process.execPath, [+ join(scriptsDir, 'batch.mjs'),+ '--input-dir', examplesDir,+ '--output-dir', batchInteractiveDir,+ '--interactive',+ ], { encoding: 'utf8' });+ assert.equal(batchInteractiveResult.status, 0, batchInteractiveResult.stderr);+ assert.match(batchInteractiveResult.stdout, /xychart\.mmd/);+ assert.match(readFileSync(join(batchInteractiveDir, 'xychart.svg'), 'utf8'), /class="xychart-tip/);++ const themedAsciiPath = join(cliTestDir, 'dracula.txt');+ const renderThemedAsciiResult = spawnSync(process.execPath, [+ join(scriptsDir, 'render.mjs'),+ '--input', flowchartPath,+ '--output', themedAsciiPath,+ '--format', 'ascii',+ '--color-mode', 'truecolor',+ '--theme', 'dracula',+ ], { encoding: 'utf8' });+ assert.equal(renderThemedAsciiResult.status, 0, renderThemedAsciiResult.stderr);+ assert.match(readFileSync(themedAsciiPath, 'utf8'), /\u001b\[38;2;248;248;242m/);++ const batchThemedAsciiDir = join(cliTestDir, 'batch-dracula');+ const batchThemedAsciiResult = spawnSync(process.execPath, [+ join(scriptsDir, 'batch.mjs'),+ '--input-dir', examplesDir,+ '--output-dir', batchThemedAsciiDir,+ '--format', 'ascii',+ '--color-mode', 'truecolor',+ '--theme', 'dracula',+ ], { encoding: 'utf8' });+ assert.equal(batchThemedAsciiResult.status, 0, batchThemedAsciiResult.stderr);+ assert.match(+ readFileSync(join(batchThemedAsciiDir, 'flowchart.txt'), 'utf8'),+ /\u001b\[38;2;248;248;242m/,+ );} finally {rmSync(cliTestDir, { recursive: true, force: true });}-console.log(`Smoke tests passed: ${files.length} diagrams x 2 formats, 15 themes, inherited theme rejection.`);+console.log(`Smoke tests passed: ${files.length} diagrams x 2 formats, 15 themes, CLI theme and interactive coverage.`);