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: reject inherited theme names
imxvb4c95a6850b8
diff --git a/scripts/batch.mjs b/scripts/batch.mjsindex 74fe822..ec14769 100644--- a/scripts/batch.mjs+++ b/scripts/batch.mjs@@ -192,7 +192,7 @@ async function main() {const opts = parseArgs();const lib = await loadBeautifulMermaid();- if (opts.theme && !lib.THEMES[opts.theme]) {+ if (opts.theme && !Object.prototype.hasOwnProperty.call(lib.THEMES, opts.theme)) {throw new Error(`Unknown theme: ${opts.theme}. Run node scripts/themes.mjs to list themes.`);}diff --git a/scripts/render.mjs b/scripts/render.mjsindex bb5bfb4..91d7813 100644--- a/scripts/render.mjs+++ b/scripts/render.mjs@@ -139,7 +139,7 @@ async function main() {const { renderMermaidSVG, renderMermaidASCII, THEMES } = await loadBeautifulMermaid();const input = readFileSync(opts.input, 'utf8');- if (opts.theme && !THEMES[opts.theme]) {+ 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.`);}diff --git a/scripts/smoke-test.mjs b/scripts/smoke-test.mjsindex 6135390..84e5239 100644--- a/scripts/smoke-test.mjs+++ b/scripts/smoke-test.mjs@@ -1,7 +1,9 @@#!/usr/bin/env nodeimport assert from 'node:assert/strict';-import { readdirSync, readFileSync } from 'node:fs';+import { spawnSync } from 'node:child_process';+import { mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';import { dirname, join } from 'node:path';import { fileURLToPath } from 'node:url';import {@@ -13,6 +15,7 @@ import {const scriptsDir = dirname(fileURLToPath(import.meta.url));const examplesDir = join(scriptsDir, '..', 'assets', 'example_diagrams');const files = readdirSync(examplesDir).filter(file => file.endsWith('.mmd')).sort();+const inheritedThemeNames = ['toString', 'constructor', '__proto__'];assert.equal(files.length, 6, 'Expected six example diagrams');assert.equal(Object.keys(THEMES).length, 15, 'Expected 15 built-in themes');@@ -26,4 +29,30 @@ for (const file of files) {assert.ok(ascii.trim().length > 0, `${file} did not render ASCII output`);}-console.log(`Smoke tests passed: ${files.length} diagrams x 2 formats, 15 themes.`);+const cliTestDir = mkdtempSync(join(tmpdir(), 'pretty-mermaid-smoke-'));+const flowchartPath = join(examplesDir, 'flowchart.mmd');++try {+ for (const themeName of inheritedThemeNames) {+ const renderResult = spawnSync(process.execPath, [+ join(scriptsDir, 'render.mjs'),+ '--input', flowchartPath,+ '--theme', themeName,+ ], { encoding: 'utf8' });+ assert.notEqual(renderResult.status, 0, `render.mjs accepted inherited theme: ${themeName}`);+ assert.match(renderResult.stderr, /Unknown theme:/);++ const batchResult = spawnSync(process.execPath, [+ join(scriptsDir, 'batch.mjs'),+ '--input-dir', examplesDir,+ '--output-dir', join(cliTestDir, themeName),+ '--theme', themeName,+ ], { encoding: 'utf8' });+ assert.notEqual(batchResult.status, 0, `batch.mjs accepted inherited theme: ${themeName}`);+ assert.match(batchResult.stderr, /Unknown theme:/);+ }+} finally {+ rmSync(cliTestDir, { recursive: true, force: true });+}++console.log(`Smoke tests passed: ${files.length} diagrams x 2 formats, 15 themes, inherited theme rejection.`);