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: support custom colors in ASCII output
imxvc56eb08a78c7
diff --git a/scripts/batch.mjs b/scripts/batch.mjsindex 1cdc0a1..dfebdba 100644--- a/scripts/batch.mjs+++ b/scripts/batch.mjs@@ -11,15 +11,21 @@ const skillRoot = join(__dirname, '..');function toAsciiTheme(colors) {if (!colors) return undefined;+ const border = colors.border ?? colors.fg;+ const line = colors.line ?? colors.fg;+ const arrow = colors.accent ?? colors.line ?? colors.fg;+ const corner = colors.border ?? colors.line ?? colors.fg;+ const junction = colors.accent ?? colors.border ?? colors.line ?? colors.fg;+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,+ ...(colors.fg && { fg: colors.fg }),+ ...(border && { border }),+ ...(line && { line }),+ ...(arrow && { arrow }),+ ...(colors.accent && { accent: colors.accent }),+ ...(colors.bg && { bg: colors.bg }),+ ...(corner && { corner }),+ ...(junction && { junction }),};}@@ -164,6 +170,14 @@ async function renderFile(file, inputDir, outputDir, opts, lib) {const outputPath = join(outputDir, file.replace(/\.mmd$/, ext));const input = readFileSync(inputPath, 'utf8');const theme = opts.theme ? THEMES[opts.theme] : undefined;+ const customColors = {+ ...(opts.bg && { bg: opts.bg }),+ ...(opts.fg && { fg: opts.fg }),+ ...(opts.line && { line: opts.line }),+ ...(opts.accent && { accent: opts.accent }),+ ...(opts.border && { border: opts.border }),+ };+ const asciiColors = theme || (Object.keys(customColors).length > 0 ? customColors : undefined);if (opts.format === 'ascii') {const ascii = renderMermaidASCII(input, {@@ -172,7 +186,7 @@ async function renderFile(file, inputDir, outputDir, opts, lib) {paddingY: opts.paddingY,boxBorderPadding: opts.boxBorderPadding,colorMode: opts.colorMode,- theme: toAsciiTheme(theme),+ theme: toAsciiTheme(asciiColors),});writeFileSync(outputPath, ascii);} else {diff --git a/scripts/render.mjs b/scripts/render.mjsindex cc67bb2..2f42629 100644--- a/scripts/render.mjs+++ b/scripts/render.mjs@@ -11,15 +11,21 @@ const skillRoot = join(__dirname, '..');function toAsciiTheme(colors) {if (!colors) return undefined;+ const border = colors.border ?? colors.fg;+ const line = colors.line ?? colors.fg;+ const arrow = colors.accent ?? colors.line ?? colors.fg;+ const corner = colors.border ?? colors.line ?? colors.fg;+ const junction = colors.accent ?? colors.border ?? colors.line ?? colors.fg;+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,+ ...(colors.fg && { fg: colors.fg }),+ ...(border && { border }),+ ...(line && { line }),+ ...(arrow && { arrow }),+ ...(colors.accent && { accent: colors.accent }),+ ...(colors.bg && { bg: colors.bg }),+ ...(corner && { corner }),+ ...(junction && { junction }),};}@@ -58,8 +64,8 @@ function parseArgs() {output: null,format: 'svg',theme: null,- bg: '#FFFFFF',- fg: '#27272A',+ bg: null,+ fg: null,font: 'Inter',transparent: false,useAscii: false,@@ -155,6 +161,14 @@ async function main() {throw new Error(`Unknown theme: ${opts.theme}. Run node scripts/themes.mjs to list themes.`);}const theme = opts.theme ? THEMES[opts.theme] : undefined;+ const customColors = {+ ...(opts.bg && { bg: opts.bg }),+ ...(opts.fg && { fg: opts.fg }),+ ...(opts.line && { line: opts.line }),+ ...(opts.accent && { accent: opts.accent }),+ ...(opts.border && { border: opts.border }),+ };+ const asciiColors = theme || (Object.keys(customColors).length > 0 ? customColors : undefined);if (opts.format === 'ascii') {const ascii = renderMermaidASCII(input, {@@ -163,7 +177,7 @@ async function main() {paddingY: opts.paddingY,boxBorderPadding: opts.boxBorderPadding,colorMode: opts.colorMode,- theme: toAsciiTheme(theme),+ theme: toAsciiTheme(asciiColors),});if (opts.output) {writeFileSync(opts.output, ascii);@@ -173,8 +187,8 @@ async function main() {}} else {const colors = theme || {- bg: opts.bg,- fg: opts.fg,+ bg: opts.bg ?? '#FFFFFF',+ fg: opts.fg ?? '#27272A',...(opts.line && { line: opts.line }),...(opts.accent && { accent: opts.accent }),...(opts.muted && { muted: opts.muted }),diff --git a/scripts/smoke-test.mjs b/scripts/smoke-test.mjsindex a0c58b7..149215b 100644--- a/scripts/smoke-test.mjs+++ b/scripts/smoke-test.mjs@@ -32,6 +32,19 @@ 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');+const customColorArgs = [+ '--bg', '#ffffff',+ '--fg', '#123456',+ '--line', '#abcdef',+ '--accent', '#fedcba',+ '--border', '#0f0f0f',+];+const customColorCodes = [+ '\u001b[38;2;18;52;86m',+ '\u001b[38;2;171;205;239m',+ '\u001b[38;2;254;220;186m',+ '\u001b[38;2;15;15;15m',+];try {for (const themeName of inheritedThemeNames) {@@ -100,8 +113,38 @@ try {readFileSync(join(batchThemedAsciiDir, 'flowchart.txt'), 'utf8'),/\u001b\[38;2;248;248;242m/,);++ const customAsciiPath = join(cliTestDir, 'custom.txt');+ const renderCustomAsciiResult = spawnSync(process.execPath, [+ join(scriptsDir, 'render.mjs'),+ '--input', flowchartPath,+ '--output', customAsciiPath,+ '--format', 'ascii',+ '--color-mode', 'truecolor',+ ...customColorArgs,+ ], { encoding: 'utf8' });+ assert.equal(renderCustomAsciiResult.status, 0, renderCustomAsciiResult.stderr);+ const customAscii = readFileSync(customAsciiPath, 'utf8');+ for (const colorCode of customColorCodes) {+ assert.ok(customAscii.includes(colorCode), `render.mjs omitted custom ASCII color ${colorCode}`);+ }++ const batchCustomAsciiDir = join(cliTestDir, 'batch-custom');+ const batchCustomAsciiResult = spawnSync(process.execPath, [+ join(scriptsDir, 'batch.mjs'),+ '--input-dir', examplesDir,+ '--output-dir', batchCustomAsciiDir,+ '--format', 'ascii',+ '--color-mode', 'truecolor',+ ...customColorArgs,+ ], { encoding: 'utf8' });+ assert.equal(batchCustomAsciiResult.status, 0, batchCustomAsciiResult.stderr);+ const batchCustomAscii = readFileSync(join(batchCustomAsciiDir, 'flowchart.txt'), 'utf8');+ for (const colorCode of customColorCodes) {+ assert.ok(batchCustomAscii.includes(colorCode), `batch.mjs omitted custom ASCII color ${colorCode}`);+ }} finally {rmSync(cliTestDir, { recursive: true, force: true });}-console.log(`Smoke tests passed: ${files.length} diagrams x 2 formats, 15 themes, CLI theme and interactive coverage.`);+console.log(`Smoke tests passed: ${files.length} diagrams x 2 formats, 15 themes, CLI named/custom colors and interactive coverage.`);