mermaid-reverse-attempt

Mermaid URL codec - encodes/decodes

⭐1stars🔀2forks📁View on GitHub🕐Updated Jan 9, 2026

When & Why to Use This Skill

The Mermaid URL Codec is a specialized utility designed to bridge the gap between Mermaid diagram source code and shareable web URLs. It supports both the #base64 (amp CLI) and #pako (mermaid.live) compression formats, allowing users to seamlessly encode diagrams into portable links or decode existing URLs back into editable Mermaid syntax. This tool is essential for developers and technical writers who need to manage, share, or recover diagram source code across different platforms and CLI tools.

Use Cases

  • Scenario 1: Quickly generate shareable mermaid.live links from local .mmd files for team reviews or documentation without manual copy-pasting.
  • Scenario 2: Extract the original Mermaid source code from a legacy or shared URL to make updates to an existing architecture diagram.
  • Scenario 3: Integrate diagram-to-URL conversion into automated CI/CD pipelines or documentation build scripts using the provided Node.js codec scripts.
  • Scenario 4: Convert between different Mermaid URL formats (e.g., from amp CLI base64 to mermaid.live pako) to ensure cross-platform compatibility.
namemermaid-reverse-attempt
description"Mermaid URL codec - encodes/decodes #base64: (amp CLI) and #pako: (mermaid.live) formats"
version1.0.0

Mermaid Reverse Attempt

Encode diagrams to shareable URLs, decode URLs back to source.

Formats Discovered

Prefix Source Method
#base64: amp CLI JSON.stringify({code}) → base64
#pako: mermaid.live pako.deflate(JSON.stringify({code})) → base64

Usage

# Encode diagram to pako URL (compressed)
node scripts/codec.js encode-pako < diagram.mmd

# Encode to base64 URL (amp style)
node scripts/codec.js encode-base64 < diagram.mmd

# Decode URL to diagram
node scripts/codec.js decode "https://mermaid.live/edit#pako:..."

Quick Reference

// Decode
const hash = url.split('#')[1];
if (hash.startsWith('pako:')) {
  return JSON.parse(pako.inflate(Buffer.from(hash.slice(5), 'base64'), {to:'string'})).code;
}
if (hash.startsWith('base64:')) {
  return JSON.parse(Buffer.from(hash.slice(7), 'base64').toString()).code;
}

// Encode pako
`https://mermaid.live/edit#pako:${Buffer.from(pako.deflate(JSON.stringify({code:diagram}))).toString('base64')}`

GF(3)

  • Trit: 0 (ERGODIC)
  • decode ∘ encode = id