Skip to content

File Tree

npm versionnpm monthly downloadsnpm sizenpm license

File tree display plugin for rendering file directory structures in Markdown.

Installation

sh
pnpm add vitepress-plugin-file-tree
sh
npm install vitepress-plugin-file-tree
sh
bun add vitepress-plugin-file-tree
sh
deno add vitepress-plugin-file-tree
sh
yarn add vitepress-plugin-file-tree

Usage

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress-tuck'
import fileTree from 'vitepress-plugin-file-tree'

export default defineConfig({
  plugins: [fileTree()],
})

Learn more about vitepress-tuck

Native Mode

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress'
import { fileTreeMarkdownPlugin } from 'vitepress-plugin-file-tree'

export default defineConfig({
  markdown: {
    config: (md) => {
      md.use(fileTreeMarkdownPlugin)
    },
  },
})
.vitepress/theme/index.ts
ts
import type { Theme } from 'vitepress'
import { enhanceAppWithFileTree } from 'vitepress-plugin-file-tree/client'
import DefaultTheme from 'vitepress/theme'

export default {
  extends: DefaultTheme,
  enhanceApp(ctx) {
    enhanceAppWithFileTree(ctx)
  },
} satisfies Theme

Syntax

Use the ::: file-tree container to represent file hierarchy via indentation:

md
::: file-tree title="Project Structure"

- src/
  - components/
    - Button.vue
    - Nav.vue
  - index.ts
- package.json
- tsconfig.json

:::

Node Annotations

Each node can have special annotations:

SyntaxDescription
**filename**Highlight/focus the file
-- filenameMark as removed
++ filenameMark as added
filename # commentAdd a comment
folder/Mark as folder, collapsed by default
Ellipsis marker
md
::: file-tree title="Changed Files"

- src/
  - -- old-file.ts
  - ++ new-file.ts
  - **main.ts** # Core entry
  -

:::

Example

md
::: file-tree

- docs
  - .vitepress
    - ++ config.ts
  - -- page1.md
  - index.md
- theme  # A **theme** directory
  - client
    - components
      - **Navbar.vue**
    - composables
      - useNavbar.ts
    - styles
      - navbar.css
    - config.ts
  - node/
- package.json
- pnpm-lock.yaml
- .gitignore
- README.md
-
:::

docs

.vitepress

config.ts

page1.md

index.md

theme# A theme directory

client

components

Navbar.vue

composables

useNavbar.ts

styles

navbar.css

config.ts

node

package.json

pnpm-lock.yaml

.gitignore

README.md

Released under the MIT License