|
| 1 | +# vitepress-plugin-tree |
| 2 | + |
| 3 | +Easy to render tree in VitePress. |
| 4 | + |
| 5 | +[document](https://zhangfisher.github.io/repos/#lite-tree) |
| 6 | + |
| 7 | +`vitepress-plugin-tree`是一个`Vue`组件,用于渲染树形结构。 |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +npm install vitepress-plugin-tree |
| 13 | +// or |
| 14 | +yarn add vitepress-plugin-tree |
| 15 | +// or |
| 16 | +pnpm add vitepress-plugin-tree |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +### Step 1: Configuration |
| 22 | + |
| 23 | +In `./vitepress/config.mts` config : |
| 24 | + |
| 25 | +```ts {5-9} |
| 26 | +// ./vitepress/config.mts |
| 27 | +import { defineConfig } from 'vitepress' |
| 28 | + |
| 29 | +export default defineConfig({ |
| 30 | + vue:{ |
| 31 | + template: { |
| 32 | + compilerOptions: { |
| 33 | + whitespace: 'preserve' |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | +}) |
| 38 | +``` |
| 39 | + |
| 40 | +### Step 2: Register the component |
| 41 | + |
| 42 | +Register `LiteTree` as a global component so that it can be used anywhere. |
| 43 | + |
| 44 | +```ts |
| 45 | +// .vitepress/theme/index.js |
| 46 | +import DefaultTheme from 'vitepress/theme' |
| 47 | +import { LiteTree } from 'vitepress-plugin-tree' |
| 48 | + |
| 49 | +/** @type {import('vitepress').Theme} */ |
| 50 | +export default { |
| 51 | + extends: DefaultTheme, |
| 52 | + enhanceApp({ app }) { |
| 53 | + app.component('Tree',LiteTree) |
| 54 | + } |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +## Step 3: Render a tree |
| 59 | + |
| 60 | +In markdown file, use `Tree` component to render tree. |
| 61 | + |
| 62 | +```vue |
| 63 | +<Tree> |
| 64 | +Root |
| 65 | + A |
| 66 | + A1 |
| 67 | + A2 |
| 68 | + B |
| 69 | + B1 |
| 70 | + B2 |
| 71 | +</Tree> |
| 72 | +``` |
| 73 | + |
| 74 | +**Use `4 spaces` or `1 TAB` to represent a tree level.** |
| 75 | + |
| 76 | +## Example |
| 77 | + |
| 78 | +```md |
| 79 | +<LiteTree> |
| 80 | +#error=color:red;border: 1px solid red;background:#ffd2d2;padding:2px; |
| 81 | +#blue=color:red;border: 1px solid blue;background:#e6e6ff;padding:2px; |
| 82 | +airplane=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxZW0iIGhlaWdodD0iMWVtIiB2aWV3Qm94PSIwIDAgMjU2IDI1NiI+PHBhdGggZmlsbD0iY3VycmVudENvbG9yIiBkPSJNMjM1LjU4IDEyOC44NEwxNjAgOTEuMDZWNDhhMzIgMzIgMCAwIDAtNjQgMHY0My4wNmwtNzUuNTggMzcuNzhBOCA4IDAgMCAwIDE2IDEzNnYzMmE4IDggMCAwIDAgOS41NyA3Ljg0TDk2IDE2MS43NnYxOC45M2wtMTMuNjYgMTMuNjVBOCA4IDAgMCAwIDgwIDIwMHYzMmE4IDggMCAwIDAgMTEgNy40M2wzNy0xNC44MWwzNyAxNC44MWE4IDggMCAwIDAgMTEtNy40M3YtMzJhOCA4IDAgMCAwLTIuMzQtNS42NkwxNjAgMTgwLjY5di0xOC45M2w3MC40MyAxNC4wOEE4IDggMCAwIDAgMjQwIDE2OHYtMzJhOCA4IDAgMCAwLTQuNDItNy4xNk0yMjQgMTU4LjI0bC03MC40My0xNC4wOEE4IDggMCAwIDAgMTQ0IDE1MnYzMmE4IDggMCAwIDAgMi4zNCA1LjY2TDE2MCAyMDMuMzF2MTYuODdsLTI5LTExLjYxYTggOCAwIDAgMC01Ljk0IDBMOTYgMjIwLjE4di0xNi44N2wxMy42Ni0xMy42NUE4IDggMCAwIDAgMTEyIDE4NHYtMzJhOCA4IDAgMCAwLTkuNTctNy44NEwzMiAxNTguMjR2LTE3LjNsNzUuNTgtMzcuNzhBOCA4IDAgMCAwIDExMiA5NlY0OGExNiAxNiAwIDAgMSAzMiAwdjQ4YTggOCAwIDAgMCA0LjQyIDcuMTZMMjI0IDE0MC45NFoiLz48L3N2Zz4= |
| 83 | +ts=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxZW0iIGhlaWdodD0iMWVtIiB2aWV3Qm94PSIwIDAgMTUgMTUiPjxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0iY3VycmVudENvbG9yIiBkPSJNMTIuNSA4di0uMTY3YzAtLjczNi0uNTk3LTEuMzMzLTEuMzMzLTEuMzMzSDEwYTEuNSAxLjUgMCAxIDAgMCAzaDFhMS41IDEuNSAwIDAgMSAwIDNoLTFBMS41IDEuNSAwIDAgMSA4LjUgMTFNOCA2LjVIM20yLjUgMFYxM00uNS41aDE0djE0SC41eiIvPjwvc3ZnPg== |
| 84 | +--- |
| 85 | +- [airplane]Company A({color:red;}Key,{#blue}Urgent) // Company Name |
| 86 | + Administrative Center |
| 87 | + {color:red;font-weight:bold;background:#ffeaea}President's Office |
| 88 | + [checked]Human Resources Department |
| 89 | + [unchecked]{.blue}Finance Department |
| 90 | + Administrative Department //+ Responsible for administrative management |
| 91 | + Legal Department //+ Litigation, etc. |
| 92 | + [airplane]Audit Department //+ Audit finance[Save:tag](sss) [Link](sss) |
| 93 | + Information Center // Key[Save](www.baidu.com)[tag][Link:tag](www.baidu.com) |
| 94 | + [star]Sec[star]ur[star]ity[star] and [star]Pro[star]tection[star] Department[star] //{color:red} Confidentiality work |
| 95 | + + Market Center |
| 96 | + Marketing Department({#error}Error,"{#warning}Warning") |
| 97 | + Sales Department //- |
| 98 | + Customer Service Department //- |
| 99 | + {#blue}Brand Department // this is cool |
| 100 | + Market Planning Department //! Key |
| 101 | + Market Marketing Department // {.blue}this is cool |
| 102 | + R&D Center |
| 103 | + Mobile R&D Department //! |
| 104 | + Platform R&D Department({success}Java,{error}Go) |
| 105 | + {.success}Testing Department |
| 106 | + Operations Department |
| 107 | + Product Department //* |
| 108 | + Design Department //* |
| 109 | + Project Management Department //* |
| 110 | +</LiteTree> |
| 111 | + |
| 112 | +``` |
| 113 | + |
| 114 | +**Rendered effect:** |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | +See [document](https://zhangfisher.github.io/repos/#lite-tree) |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
0 commit comments