Skip to content

From Mermaid or JSON ​

Every API and CLI command accepts three input formats and detects the format from the content.

Mermaid ​

Mermaid diagrams render as they are. Flowcharts become a yuhwa graph. Most other diagram types become a panel or nodes and groups:

yuhwa diagramyuhwa diagramEdit
yuhwa
flowchart LR
  A[Start] --> B{Valid?}
  B -->|yes| C((Done))
  B -.->|no| D[(Error log)]
  subgraph svc [Service]
    C
  end

Convert one to yuhwa source to restyle it:

sh
yuhwa convert flow.mmd -o flow.yu

What converts ​

Mermaidyuhwa
graph, flowchartnodes, edges and groups
stateDiagram, stateDiagram-v2nodes and groups. [*], fork, join and choice states get small classes such as .state-start. Composite states become groups
classDiagramcard nodes (attributes, ---, methods). Inheritance, composition and dependency become edges with head/tail markers. Cardinalities become the edge caption. Namespaces become groups
erDiagraman entity block becomes a node with a type | name | keys | comment table. A relationship becomes an edge with the cardinality as caption
sequenceDiagramsequence panel
timelinetimeline panel
gitGraphgit panel
piechart panel, type: pie
xychart-betachart panel, bar or line
journeychart panel, one column per task score, coloured by score
mindmapmindmap panel
ganttgantt panel
quadrantChartquadrant panel
kanbankanban panel

The gantt, quadrant and kanban panels come from plugins. Register a plugin with use() before you render its panel.

Flowchart details:

Mermaidyuhwa
TD TB LR RL BTdirection
A[x] A(x)default shape
A{x} A A[(x)] A((x)) A([x]) A[/x/]diamond, hexagon, cylinder, circle, pill, parallelogram
--> --- -.-> ==> <-->-> -- ..> => <->
-->|label| and -- label -->edge label
subgraph id [Title] … endgroup
classDef, class, :::name, styleclasses and props

Mermaid style and classDef colours pass through: fill and stroke keep their hex or rgb() value. Mermaid's color is the text colour, so it becomes text. yuhwa's own color prop sets the palette colour of a node.

What gives a warning ​

The converter keeps going and lists what it skipped or changed:

  • click, linkStyle, accTitle and accDescr are skipped.
  • A direction inside a subgraph or composite state is skipped.
  • Sequence loop, alt, opt and par blocks become --- … --- dividers. rect boxes and activations are skipped. Cross ends (-x) are drawn as normal arrows.
  • State concurrency regions (--) are drawn as one region. Edges to a composite state attach to its start or end state inside.
  • Class aggregation (o--) is drawn as a diamond, like composition.
  • Journey actors are skipped. The scores become a column chart.
  • xychart-beta y-axis titles and ranges are skipped; the chart scales to the data.
  • Mindmap icons and classes are skipped. Cloud, bang and hexagon shapes use the default look.
  • Gantt excludes, a dateFormat other than YYYY-MM-DD, and lengths in seconds or minutes are approximated.
  • Kanban priority Very High becomes high, Very Low becomes low.

What gives an error ​

These types have no yuhwa equivalent yet: sankey-beta, C4Context and the other C4 types, requirementDiagram, packet-beta, block-beta, architecture-beta, radar-beta, treemap-beta and zenuml.

What yuhwa does better ​

Mermaidyuhwa
styles repeat on every node, or need classDef plus class lines.svc [blue] once, .primary .svc [bold] to extend
colours are CSS strings per diagram typeone palette everywhere: [red], [color: teal], or a hex, rgb() or hsl() value
no variables$brand: violet, then color: $brand anywhere
no reuse of node patternsdef service(id, label) { … }, then service(cart, "Cart")
one file per diagramimport, with export lists and import { a as b }
one diagram type per blocka graph and any number of panels (sequence, chart, git, gantt, …) in one file
positions cannot be fixeddrag in the editor; positions land in a layout { } block
a gantt task needs an id and a date formatdesign "Design": 2024-01-01, 10d, and the next task follows on its own
kanban metadata is a YAML-like @{ } blockchips: - Fix login [owner: ana, priority: high]
a class or ER diagram is its own syntaxthey are ordinary nodes, so classes, groups and themes apply
errors stop the renderwarnings with line numbers and did you mean hints; the rest still renders

JSON ​

Programs and tool-calling models can send structured data instead of text. The object has optional title, direction, theme, settings, classes, groups, nodes and edges keys. Any other key on a node, edge or group is a prop.

json
{
  "title": "Checkout",
  "direction": "down",
  "classes": { "svc": { "color": "blue" } },
  "groups": [{ "id": "core", "label": "Core", "color": "slate" }],
  "nodes": [
    { "id": "api", "label": "API", "group": "core", "class": "svc", "sub": "Node 22" },
    { "id": "db", "label": "Postgres", "shape": "cylinder" }
  ],
  "edges": [{ "from": "api", "to": ["db", "cache"], "label": "read", "arrow": "-->" }]
}
  • groups[].parent nests a group in another one.
  • edges[].from and edges[].to take an id or a list of ids (fan-out).
  • edges[].arrow is one of the arrows. The default is ->.
  • class takes a name or a list of names.

render() also accepts the object directly. yuhwa convert diagram.json prints the equivalent yuhwa source.

In the editor ​

Import in the visual editor takes Mermaid, JSON or yuhwa: paste it, pick a file, or drop one on the window. The editor converts it and opens the result as a new file tab, or replaces the current one. A Markdown file works too: the first yuhwa, mermaid or json fence is imported.

Released under the MIT License.