explaingit

lukilabs/beautiful-mermaid

8,953TypeScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A TypeScript library that renders Mermaid diagram code into clean SVG images or ASCII art for terminals, with no browser required, 15 built-in color themes, and synchronous output that works inside React components.

Mindmap

mindmap
  root((repo))
    What it does
      SVG rendering
      ASCII art output
      No browser needed
    Diagram types
      Flowcharts
      Sequence diagrams
      Class and ER
    Theming
      15 built-in themes
      Two-color system
      Live CSS switching
    Tech
      TypeScript
      npm package
      React compatible
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Render Mermaid flowcharts or sequence diagrams to SVG inside a Node.js server or CLI tool without needing a browser.

USE CASE 2

Display diagrams as ASCII art in a terminal application using Unicode box-drawing characters.

USE CASE 3

Add diagram rendering to a React component that re-renders without flicker, using the synchronous output with memoization.

USE CASE 4

Apply a color theme like Dracula, Nord, or Catppuccin to diagrams in a documentation tool by providing a background and foreground color.

Tech stack

TypeScriptnpm

Getting it running

Difficulty · easy Time to first run · 30min

Install via npm, works in any JavaScript environment with no browser or DOM required.

In plain English

beautiful-mermaid is a TypeScript library for rendering Mermaid diagrams as clean SVG images or as ASCII art for terminals. Mermaid is a popular text-based format for writing diagrams in plain text, and this library provides an alternative renderer focused on visual quality and flexibility compared to the official Mermaid renderer. The library was built by the team behind Craft, a note-taking and document tool, to power diagrams inside their AI agent product. The README describes motivations as: the default Mermaid renderer requires a browser DOM and can be slow, its theming involves CSS complexity, and it cannot render to text for command-line tools. This library addresses all three by running in pure TypeScript with no browser dependencies, supporting ASCII output alongside SVG, and using a simple two-color theming system. The theming approach is one of the library's main features. You provide a background color and a foreground color, and the library derives all other diagram element colors automatically. For more control, you can supply additional optional colors for specific elements. Fifteen built-in themes are included, covering common editor and IDE color schemes like Tokyo Night, Catppuccin, Nord, Dracula, GitHub, Solarized, and One Dark. Themes can also be switched live using CSS custom properties without re-rendering. Rendering is synchronous rather than asynchronous, which makes it straightforward to use inside React components with memoization, avoiding the flickering that can occur when diagram rendering happens in side effects. The library supports flowcharts, state diagrams, sequence diagrams, class diagrams, entity-relationship diagrams, and XY charts including bar and line charts. The ASCII output uses Unicode box-drawing characters to produce terminal-friendly diagrams, adapted from an earlier Go project. The package is available on npm and works in any JavaScript environment.

Copy-paste prompts

Prompt 1
Show me how to use beautiful-mermaid to render this flowchart definition to an SVG string in a Node.js script: 'graph TD, A-->B, B-->C,'
Prompt 2
I want to print a Mermaid sequence diagram as ASCII art in a terminal. Show me the beautiful-mermaid code to do that, including how to install the package.
Prompt 3
How do I use beautiful-mermaid inside a React component so the diagram renders synchronously without flickering? Show the component code with memoization.
Prompt 4
I want to use the Tokyo Night theme from beautiful-mermaid. Show me how to pass the theme colors and render a class diagram to SVG.
Open on GitHub → Explain another repo

← lukilabs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.