mermaid-check

mermaid-check is a skill for Claude Code from ranxi2001/zero2Agent. It costs 83 tokens per session (2,456 once invoked), scanned B, original, MIT.

A checker for Mermaid diagrams, which are text descriptions of flowcharts and other diagrams. It focuses on Mermaid 9.4.3 diagrams in the zero2Agent project and can help fix syntax errors that stop them rendering.

In plain words
What is it for?
Use it to check flowcharts and other Mermaid blocks, investigate rendering failures, and validate diagram syntax with the Mermaid command-line tool.
Why use it?
It helps find why a diagram shows an error or fails to appear in a page. It also explains how the project converts HTML-escaped diagram text before Mermaid parses it.

Skill for Claude Code

Written for Claude Code: installed under .claude/.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/ranxi2001/zero2agent/mermaid-check
Any agent
npx skills add ranxi2001/zero2Agent --skill mermaid-check
Clone the repo
git clone --depth 1 https://github.com/ranxi2001/zero2Agent

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for mermaid-check

README.md
[![agentmods](https://agentmods.dev/badge/skills/ranxi2001/zero2agent/mermaid-check.svg)](https://agentmods.dev/skills/ranxi2001/zero2agent/mermaid-check)
Your own site
<a href="https://agentmods.dev/skills/ranxi2001/zero2agent/mermaid-check"><img src="https://agentmods.dev/badge/skills/ranxi2001/zero2agent/mermaid-check.svg" alt="Measured on agentmods" height="20"></a>
Per session 83 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,456 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 2 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00083 $0.02456
Opus 5 $0.00042 $0.01228
Sonnet 5 $0.00017 $0.00491
Haiku 4.5 $0.00008 $0.00246

Measured 6d ago against content hash c8c17930c718, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade B, and why

mermaid-check scanned grade B with 2 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Reads agent configuration directoriesmediumAgent snooping

.claude/, .codex/, .gemini/ hold keys, settings and other credentials a mod has no legitimate need for.

grep -rn '```mermaid' --include="*.md" . | grep -v ".claude/"

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

result = subprocess.run(
.claude/skills/mermaid-check/SKILL.md · 244 lines

How it starts

The opening of the file, as written. The whole thing — 244 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Mermaid 语法检查与修复

本项目使用 mermaid 9.4.3(CDN 加载),配置 htmlLabels: falsesecurityLevel: 'loose'。 图表写在 ```mermaid 代码围栏中,由 _layouts/default.html 中的 JS 转换后渲染。


渲染管线原理

```mermaid 代码围栏
  ↓ kramdown 渲染
<div class="language-mermaid"><code>原始文本(HTML 实体转义)</code></div>
  ↓ 项目 JS(default.html)
code.textContent → 原始 mermaid 文本(含 <br>、-->、| 等)
  ↓ srcToInnerHTML() 转换
innerHTML: 转义 < > & 但保留 <br/> 为真实 HTML 标签
  ↓ mermaid.init()
读取 innerHTML → entityDecode() → 解析器

关键函数 srcToInnerHTML

function srcToInnerHTML(src) {
    return src
        .replace(/&/g, '&amp;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/&lt;br\s*\/?&gt;/gi, '<br/>');
}

原理:先将所有 HTML 特殊字符转义,再把 <br> 从实体还原为真实标签。 mermaid 的 entityDecode 通过 escape()/unescape() 能正确处理:

  • --&gt; → 解码回 -->
  • <br/> (真实标签) → escape 变为 %3Cbr/%3E → unescape 变回 <br/>
  • | → escape 变为 %7C → unescape 变回 |

使用 Node.js 验证 mermaid 语法

安装 mermaid CLI:

npm install -g @mermaid-js/mermaid-cli

验证单个图表:

echo 'flowchart LR
    A[text] -->|label| B' > /tmp/test.mmd
npx mmdc -i /tmp/test.mmd -o /tmp/test.svg 2>&1

批量验证项目中所有 mermaid 块:

python3 << 'EOF'
import re, os, subprocess, tempfile

base = os.getcwd()
errors = []
for root, dirs, files in os.walk(base):
    dirs[:] = [d for d in dirs if d not in ['.git', '.claude', 'node_modules']]
    for f in files:
        if not f.endswith('.md'): continue
        path = os.path.join(root, f)
        with open(path) as fh:
            content = fh.read()
        for m in re.finditer(r'```mermaid\n(.*?)\n```', content, re.DOTALL):
            block = m.group(1)
            line = content[:m.start()].count('\n') + 1
            with tempfile.NamedTemporaryFile(suffix='.mmd', mode='w', delete=False) as tmp:
                tmp.write(block)
                tmp_path = tmp.name
            result = subprocess.run(
                ['npx', 'mmdc', '-i', tmp_path, '-o', '/dev/null'],
                capture_output=True, text=True
            )
            os.unlink(tmp_path)
            if result.returncode != 0:
                errors.append((path, line, result.stderr.strip()))

Read the full file on GitHub · 244 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 244 lines · 83 tokens per session scan B c8c17930c718

Subscribe to this mod's changes

mermaid-check is a skill published in the GitHub repository ranxi2001/zero2Agent (401 stars, last pushed yesterday), licensed MIT. It adds 83 tokens to every session and 2,456 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it B with 2 findings (reads agent configuration directories, runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.