Skip to content

TreeΒ€

Markdown Exec provides a tree formatter that can be used to render file-system trees easily:

```tree
root1
    file1
    dir1
        file
    dir2
        file1
        file2
    file2
    file3
root2
    file1
```
πŸ“ root1
β”œβ”€β”€  file1
β”œβ”€β”€ πŸ“ dir1
β”‚   └──  file
β”œβ”€β”€ πŸ“ dir2
β”‚   β”œβ”€β”€  file1
β”‚   └──  file2
β”œβ”€β”€  file2
└──  file3
πŸ“ root2
└──  file1

Syntax highlightΒ€

By default, the language used for syntax highlight is bash. It means you can add comments with #:

```tree
root1            # comment 1
    file1
    dir1
        file
    dir2
        file1    # comment 2
        file2    # comment 3
    file2
    file3
root2
    file1
```
πŸ“ root1            # comment 1
β”œβ”€β”€  file1
β”œβ”€β”€ πŸ“ dir1
β”‚   └──  file
β”œβ”€β”€ πŸ“ dir2
β”‚   β”œβ”€β”€  file1    # comment 2
β”‚   └──  file2    # comment 3
β”œβ”€β”€  file2
└──  file3
πŸ“ root2
└──  file1

You can change the syntax highlight language with the result option:

```tree result="javascript"
root1            // comment 1
    file1
    dir1
        file
    dir2
        file1    // comment 2
        file2    // comment 3
    file2
    file3
root2
    file1
```
πŸ“ root1            // comment 1
β”œβ”€β”€  file1
β”œβ”€β”€ πŸ“ dir1
β”‚   └──  file
β”œβ”€β”€ πŸ“ dir2
β”‚   β”œβ”€β”€  file1    // comment 2
β”‚   └──  file2    // comment 3
β”œβ”€β”€  file2
└──  file3
πŸ“ root2
└──  file1

Leaf directoriesΒ€

You can force an entry to be displayed as a directory instead of a regular file by appending a trailing slash to the name:

```tree
root1
    dir1/
    dir2/
    dir3/
```
πŸ“ root1
β”œβ”€β”€ πŸ“ dir1/
β”œβ”€β”€ πŸ“ dir2/
└── πŸ“ dir3/

It is recommended to always append trailing slashes to directories anyway.

Limitation

Spaces in file names are not supported when searching for a trailing slash.

Custom iconsΒ€

Sponsors only Insiders 1.1.0

Custom icons based on the file name and extension can be used in tree fences. This feature requires that the Material for MkDocs theme is used. By default, if Material for MkDocs is used, custom icons will be rendered. You can opt-out with icons="basic" to use the basic folder and file emojis, or even remove all icons/emojis with icons="none".

```tree icons="none"
folder/
    file
    file.py
    file.rb
    file.js
```
folder/
β”œβ”€β”€ file
β”œβ”€β”€ file.py
β”œβ”€β”€ file.rb
└── file.js
```tree icons="basic"
folder/
    file
    file.py
    file.rb
    file.rs
```
πŸ“ folder/
β”œβ”€β”€ πŸ“„ file
β”œβ”€β”€ πŸ“„ file.py
β”œβ”€β”€ πŸ“„ file.rb
└── πŸ“„ file.rs
```tree icons="material"
folder/
    file
    file.py
    file.rb
    file.rs
```
πŸ“ folder/
β”œβ”€β”€  file
β”œβ”€β”€  file.py
β”œβ”€β”€  file.rb
└──  file.rs
```tree icons="auto"
folder/
    file
    file.py
    file.rb
    file.rs
```
πŸ“ folder/
β”œβ”€β”€  file
β”œβ”€β”€  file.py
β”œβ”€β”€  file.rb
└──  file.rs