Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/add-treeview-box-drawing-input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'mermaid': minor
---

feat: add box-drawing character input support for treeView diagrams

Adds an alternative input syntax for treeView-beta diagrams using box-drawing characters (β”œβ”€β”€, └──, β”‚). The parser auto-detects box-drawing format and converts it to the standard indent-based representation before parsing. Error messages remap line numbers back to the original input. Includes 42 unit tests and 4 AST equivalence integration tests.
38 changes: 38 additions & 0 deletions demos/treeView.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,44 @@ <h2>Folder Names with Spaces</h2>
</div>
</div>

<h2>Box-Drawing Input</h2>
<div class="demo">
<pre class="source"></pre>
<div class="rendered">
<pre class="mermaid">
treeView-beta
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ components/
β”‚ β”‚ β”œβ”€β”€ Button.tsx
β”‚ β”‚ └── Modal.tsx
β”‚ β”œβ”€β”€ utils/
β”‚ β”‚ └── helpers.ts
β”‚ └── index.js
β”œβ”€β”€ docs/
β”‚ └── README.md
β”œβ”€β”€ package.json
└── .gitignore
</pre>
</div>
</div>

<h2>Box-Drawing with Annotations</h2>
<div class="demo">
<pre class="source"></pre>
<div class="rendered">
<pre class="mermaid">
treeView-beta
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ App.tsx :::highlight ## main component
β”‚ β”œβ”€β”€ index.js ## entry point
β”‚ └── config.ts
β”œβ”€β”€ docs/
β”‚ └── guide.md ## user guide
└── package.json
</pre>
</div>
</div>

<h2>Custom Config</h2>
<div class="demo">
<pre class="source"></pre>
Expand Down
76 changes: 76 additions & 0 deletions docs/syntax/treeView.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,82 @@ treeView-beta
"file.js"
```

## Box-Drawing Input

As an alternative to indentation, you can use box-drawing characters to define the tree structure. The parser auto-detects the format β€” no extra keyword or config is needed. This is how most file tree diagrams are drawn already, so you can turn those into Mermaid diagrams with very little effort.

Both standard (`β”œβ”€β”€`, `└──`, `β”‚`) and heavy (`┣━━`, `┗━━`, `┃`) Unicode variants are supported.

```mermaid-example
treeView-beta
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ index.ts
β”‚ └── utils.ts
β”œβ”€β”€ package.json
└── README.md
```

```mermaid
treeView-beta
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ index.ts
β”‚ └── utils.ts
β”œβ”€β”€ package.json
└── README.md
```

All annotations work the same way β€” just append them after the label:

```mermaid-example
treeView-beta
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ App.tsx :::highlight icon(react) ## main component
β”‚ └── index.ts ## entry point
β”œβ”€β”€ .env ## environment variables
β”œβ”€β”€ Dockerfile
└── package.json
```

```mermaid
treeView-beta
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ App.tsx :::highlight icon(react) ## main component
β”‚ └── index.ts ## entry point
β”œβ”€β”€ .env ## environment variables
β”œβ”€β”€ Dockerfile
└── package.json
```

Depth is inferred from the column position of the branch character, so deeper nesting works naturally:

```mermaid-example
treeView-beta
β”œβ”€β”€ packages/
β”‚ β”œβ”€β”€ mermaid/
β”‚ β”‚ β”œβ”€β”€ src/
β”‚ β”‚ β”‚ β”œβ”€β”€ parser.ts
β”‚ β”‚ β”‚ └── renderer.ts
β”‚ β”‚ └── package.json
β”‚ └── parser/
β”‚ └── src/
└── README.md
```

```mermaid
treeView-beta
β”œβ”€β”€ packages/
β”‚ β”œβ”€β”€ mermaid/
β”‚ β”‚ β”œβ”€β”€ src/
β”‚ β”‚ β”‚ β”œβ”€β”€ parser.ts
β”‚ β”‚ β”‚ └── renderer.ts
β”‚ β”‚ └── package.json
β”‚ └── parser/
β”‚ └── src/
└── README.md
```

> **Note:** If a parse error occurs, line numbers in the error message refer to your original input. Tab characters are automatically expanded to spaces.

## Annotations

### Highlighting with :::class
Expand Down
Loading
Loading