vitepress-plugin-file-tree 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/browser/index.js +15 -53
- package/dist/client/ssr/index.js +17 -55
- package/dist/node/index.js +25 -226
- package/package.json +4 -4
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import "../style.css";
|
|
2
2
|
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, defineComponent, inject, mergeProps, normalizeClass, openBlock, ref, renderSlot, toDisplayString, unref, vShow, withDirectives } from "vue";
|
|
3
3
|
import { VPCopyButton } from "vitepress-plugin-toolkit/client";
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
const _hoisted_1$1 = {
|
|
6
6
|
key: 0,
|
|
7
7
|
class: "vp-file-tree-title"
|
|
8
8
|
};
|
|
9
9
|
const _hoisted_2$1 = { class: "file-tree-content" };
|
|
10
|
-
const _sfc_main =
|
|
10
|
+
const _sfc_main = defineComponent({
|
|
11
11
|
__name: "VPFileTree",
|
|
12
12
|
props: {
|
|
13
13
|
title: {},
|
|
@@ -27,22 +27,14 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* File tree node click event
|
|
34
|
-
*
|
|
35
|
-
* 文件树节点点击事件
|
|
36
|
-
*/
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
37
33
|
const ON_NODE_CLICK = Symbol(import.meta.env.DEV ? "on-file-tree-node-click" : "");
|
|
38
|
-
|
|
39
|
-
* Active file tree node
|
|
40
|
-
*
|
|
41
|
-
* 当前激活的文件树节点
|
|
42
|
-
*/
|
|
34
|
+
|
|
43
35
|
const ACTIVE_NODE_KEY = Symbol(import.meta.env.DEV ? "active-file-tree-node" : "");
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
|
|
37
|
+
|
|
46
38
|
const _hoisted_1 = { class: "vp-file-tree-node" };
|
|
47
39
|
const _hoisted_2 = ["data-filename"];
|
|
48
40
|
const _hoisted_3 = {
|
|
@@ -53,7 +45,7 @@ const _hoisted_4 = {
|
|
|
53
45
|
key: 0,
|
|
54
46
|
class: "group"
|
|
55
47
|
};
|
|
56
|
-
const _sfc_main$1 =
|
|
48
|
+
const _sfc_main$1 = defineComponent({
|
|
57
49
|
__name: "VPFileTreeNode",
|
|
58
50
|
props: {
|
|
59
51
|
type: {},
|
|
@@ -68,30 +60,12 @@ const _sfc_main$1 = /*@__PURE__*/ defineComponent({
|
|
|
68
60
|
const activeFileTreeNode = inject(ACTIVE_NODE_KEY, ref(""));
|
|
69
61
|
const onNodeClick = inject(ON_NODE_CLICK, () => {});
|
|
70
62
|
const active = ref(__props.expanded);
|
|
71
|
-
|
|
72
|
-
* Notify the parent of a node click event via the injected callback.
|
|
73
|
-
*
|
|
74
|
-
* 通过注入的回调通知父组件节点点击事件。
|
|
75
|
-
*
|
|
76
|
-
* Ellipsis placeholders (`…` or `...`) are ignored to avoid triggering
|
|
77
|
-
* selection on empty folder markers.
|
|
78
|
-
*/
|
|
63
|
+
|
|
79
64
|
function nodeClick() {
|
|
80
65
|
if (__props.filename === "…" || __props.filename === "...") return;
|
|
81
66
|
onNodeClick(__props.filepath || __props.filename, __props.type);
|
|
82
67
|
}
|
|
83
|
-
|
|
84
|
-
* Handle click events on the node, toggling folder expansion or firing
|
|
85
|
-
* the node click callback for files.
|
|
86
|
-
*
|
|
87
|
-
* 处理节点的点击事件,切换文件夹展开状态或触发文件节点的点击回调。
|
|
88
|
-
*
|
|
89
|
-
* For folders, clicks on the comment area are ignored so that inline
|
|
90
|
-
* comments remain interactive. For files, the click callback fires
|
|
91
|
-
* directly.
|
|
92
|
-
*
|
|
93
|
-
* @param ev - Native mouse event / 原生鼠标事件
|
|
94
|
-
*/
|
|
68
|
+
|
|
95
69
|
function toggle(ev) {
|
|
96
70
|
if (__props.type === "folder") {
|
|
97
71
|
if (!ev.target.matches(".comment, .comment *")) {
|
|
@@ -127,24 +101,12 @@ const _sfc_main$1 = /*@__PURE__*/ defineComponent({
|
|
|
127
101
|
};
|
|
128
102
|
}
|
|
129
103
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
* Register file tree components globally during VitePress app enhancement.
|
|
134
|
-
*
|
|
135
|
-
* 在 VitePress 应用增强阶段全局注册文件树组件。
|
|
136
|
-
*
|
|
137
|
-
* Called automatically by the `virtual:enhance-app` module when the plugin
|
|
138
|
-
* is loaded via `vitepress-tuck`'s `defineConfig`. Registers `VPFileTree`
|
|
139
|
-
* and `VPFileTreeNode` as global Vue components so they can be used in
|
|
140
|
-
* markdown-rendered HTML without explicit imports.
|
|
141
|
-
*
|
|
142
|
-
* @param ctx - VitePress enhance app context / VitePress 应用增强上下文
|
|
143
|
-
* @param ctx.app - The VitePress Vue app instance / VitePress 的 Vue 应用实例
|
|
144
|
-
*/
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
145
107
|
function enhanceAppWithFileTree({ app }) {
|
|
146
108
|
if (!app._context.components.VPFileTree) app.component("VPFileTree", _sfc_main);
|
|
147
109
|
if (!app._context.components.VPFileTreeNode) app.component("VPFileTreeNode", _sfc_main$1);
|
|
148
110
|
}
|
|
149
|
-
|
|
111
|
+
|
|
150
112
|
export { ACTIVE_NODE_KEY, ON_NODE_CLICK, _sfc_main as VPFileTree, _sfc_main$1 as VPFileTreeNode, enhanceAppWithFileTree };
|
package/dist/client/ssr/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { computed, defineComponent, inject, mergeProps, ref, unref, useSSRContext } from "vue";
|
|
2
2
|
import { ssrInterpolate, ssrRenderAttr, ssrRenderAttrs, ssrRenderClass, ssrRenderComponent, ssrRenderSlot, ssrRenderStyle } from "vue/server-renderer";
|
|
3
3
|
import { VPCopyButton } from "vitepress-plugin-toolkit/client";
|
|
4
|
-
|
|
5
|
-
const _sfc_main =
|
|
4
|
+
|
|
5
|
+
const _sfc_main = defineComponent({
|
|
6
6
|
__name: "VPFileTree",
|
|
7
7
|
__ssrInlineRender: true,
|
|
8
8
|
props: {
|
|
@@ -28,26 +28,18 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
28
28
|
const _sfc_setup$1 = _sfc_main.setup;
|
|
29
29
|
_sfc_main.setup = (props, ctx) => {
|
|
30
30
|
const ssrContext = useSSRContext();
|
|
31
|
-
(ssrContext.modules || (ssrContext.modules =
|
|
31
|
+
(ssrContext.modules || (ssrContext.modules = new Set())).add("src/client/VPFileTree.vue");
|
|
32
32
|
return _sfc_setup$1 ? _sfc_setup$1(props, ctx) : void 0;
|
|
33
33
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* File tree node click event
|
|
38
|
-
*
|
|
39
|
-
* 文件树节点点击事件
|
|
40
|
-
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
41
37
|
const ON_NODE_CLICK = Symbol(import.meta.env.DEV ? "on-file-tree-node-click" : "");
|
|
42
|
-
|
|
43
|
-
* Active file tree node
|
|
44
|
-
*
|
|
45
|
-
* 当前激活的文件树节点
|
|
46
|
-
*/
|
|
38
|
+
|
|
47
39
|
const ACTIVE_NODE_KEY = Symbol(import.meta.env.DEV ? "active-file-tree-node" : "");
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const _sfc_main$1 =
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const _sfc_main$1 = defineComponent({
|
|
51
43
|
__name: "VPFileTreeNode",
|
|
52
44
|
__ssrInlineRender: true,
|
|
53
45
|
props: {
|
|
@@ -63,30 +55,12 @@ const _sfc_main$1 = /*@__PURE__*/ defineComponent({
|
|
|
63
55
|
const activeFileTreeNode = inject(ACTIVE_NODE_KEY, ref(""));
|
|
64
56
|
const onNodeClick = inject(ON_NODE_CLICK, () => {});
|
|
65
57
|
const active = ref(__props.expanded);
|
|
66
|
-
|
|
67
|
-
* Notify the parent of a node click event via the injected callback.
|
|
68
|
-
*
|
|
69
|
-
* 通过注入的回调通知父组件节点点击事件。
|
|
70
|
-
*
|
|
71
|
-
* Ellipsis placeholders (`…` or `...`) are ignored to avoid triggering
|
|
72
|
-
* selection on empty folder markers.
|
|
73
|
-
*/
|
|
58
|
+
|
|
74
59
|
function nodeClick() {
|
|
75
60
|
if (__props.filename === "…" || __props.filename === "...") return;
|
|
76
61
|
onNodeClick(__props.filepath || __props.filename, __props.type);
|
|
77
62
|
}
|
|
78
|
-
|
|
79
|
-
* Handle click events on the node, toggling folder expansion or firing
|
|
80
|
-
* the node click callback for files.
|
|
81
|
-
*
|
|
82
|
-
* 处理节点的点击事件,切换文件夹展开状态或触发文件节点的点击回调。
|
|
83
|
-
*
|
|
84
|
-
* For folders, clicks on the comment area are ignored so that inline
|
|
85
|
-
* comments remain interactive. For files, the click callback fires
|
|
86
|
-
* directly.
|
|
87
|
-
*
|
|
88
|
-
* @param ev - Native mouse event / 原生鼠标事件
|
|
89
|
-
*/
|
|
63
|
+
|
|
90
64
|
function toggle(ev) {
|
|
91
65
|
if (__props.type === "folder") {
|
|
92
66
|
if (!ev.target.matches(".comment, .comment *")) {
|
|
@@ -132,27 +106,15 @@ const _sfc_main$1 = /*@__PURE__*/ defineComponent({
|
|
|
132
106
|
const _sfc_setup = _sfc_main$1.setup;
|
|
133
107
|
_sfc_main$1.setup = (props, ctx) => {
|
|
134
108
|
const ssrContext = useSSRContext();
|
|
135
|
-
(ssrContext.modules || (ssrContext.modules =
|
|
109
|
+
(ssrContext.modules || (ssrContext.modules = new Set())).add("src/client/VPFileTreeNode.vue");
|
|
136
110
|
return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
|
|
137
111
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
* Register file tree components globally during VitePress app enhancement.
|
|
142
|
-
*
|
|
143
|
-
* 在 VitePress 应用增强阶段全局注册文件树组件。
|
|
144
|
-
*
|
|
145
|
-
* Called automatically by the `virtual:enhance-app` module when the plugin
|
|
146
|
-
* is loaded via `vitepress-tuck`'s `defineConfig`. Registers `VPFileTree`
|
|
147
|
-
* and `VPFileTreeNode` as global Vue components so they can be used in
|
|
148
|
-
* markdown-rendered HTML without explicit imports.
|
|
149
|
-
*
|
|
150
|
-
* @param ctx - VitePress enhance app context / VitePress 应用增强上下文
|
|
151
|
-
* @param ctx.app - The VitePress Vue app instance / VitePress 的 Vue 应用实例
|
|
152
|
-
*/
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
153
115
|
function enhanceAppWithFileTree({ app }) {
|
|
154
116
|
if (!app._context.components.VPFileTree) app.component("VPFileTree", _sfc_main);
|
|
155
117
|
if (!app._context.components.VPFileTreeNode) app.component("VPFileTreeNode", _sfc_main$1);
|
|
156
118
|
}
|
|
157
|
-
|
|
119
|
+
|
|
158
120
|
export { ACTIVE_NODE_KEY, ON_NODE_CLICK, _sfc_main as VPFileTree, _sfc_main$1 as VPFileTreeNode, enhanceAppWithFileTree };
|
package/dist/node/index.js
CHANGED
|
@@ -1,38 +1,8 @@
|
|
|
1
1
|
import { definePlugin } from "vitepress-tuck";
|
|
2
2
|
import { createContainerSyntaxPlugin, stringifyAttrs } from "vitepress-plugin-toolkit";
|
|
3
3
|
import { removeTrailingSlash } from "@pengzhanbo/utils";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Convert file tree nodes into `tree` command-style plain text.
|
|
7
|
-
*
|
|
8
|
-
* 将文件树节点转换为 `tree` 命令风格的纯文本。
|
|
9
|
-
*
|
|
10
|
-
* Produces a string representation using `├──` and `└──` branch markers with
|
|
11
|
-
* `│ ` and ` ` indentation, matching the output of the Unix `tree`
|
|
12
|
-
* command. Ellipsis placeholder children (`…`) are filtered out so empty
|
|
13
|
-
* folders render cleanly. The result is used by the copy button on the
|
|
14
|
-
* rendered file tree.
|
|
15
|
-
*
|
|
16
|
-
* 使用 `├──` 和 `└──` 分支标记以及 `│` 和空格缩进生成字符串表示,与 Unix `tree` 命令的输出一致。
|
|
17
|
-
* 省略号占位符子项(`…`)会被过滤掉,使得空文件夹显示整洁。该结果用于渲染文件树上的复制按钮。
|
|
18
|
-
*
|
|
19
|
-
* @param nodes - File tree nodes to convert / 要转换的文件树节点数组
|
|
20
|
-
* @param prefix - Line prefix for recursive indentation / 递归缩进使用的行前缀
|
|
21
|
-
* @returns CMD-style text representation / CMD 风格的文本表示
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* const nodes = [
|
|
26
|
-
* { filename: 'src', type: 'folder', level: 0, children: [
|
|
27
|
-
* { filename: 'index.ts', type: 'file', level: 1, children: [] },
|
|
28
|
-
* ]},
|
|
29
|
-
* ]
|
|
30
|
-
* fileTreeToCMDText(nodes)
|
|
31
|
-
* // .
|
|
32
|
-
* // └── src
|
|
33
|
-
* // └── index.ts
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
4
|
+
|
|
5
|
+
|
|
36
6
|
function fileTreeToCMDText(nodes, prefix = "") {
|
|
37
7
|
let content = prefix ? "" : ".\n";
|
|
38
8
|
for (let i = 0, l = nodes.length; i < l; i++) {
|
|
@@ -43,44 +13,11 @@ function fileTreeToCMDText(nodes, prefix = "") {
|
|
|
43
13
|
}
|
|
44
14
|
return content;
|
|
45
15
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* Regular expression for the focus marker `**filename**`.
|
|
50
|
-
*
|
|
51
|
-
* 聚焦标记 `**filename**` 的正则表达式。
|
|
52
|
-
*
|
|
53
|
-
* A filename wrapped in double asterisks is highlighted as a focused node.
|
|
54
|
-
* The marker may be followed by a space and an inline comment.
|
|
55
|
-
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
56
19
|
const RE_FOCUS = /^\*\*(.*?)\*\*(?:$|\s+)/;
|
|
57
|
-
|
|
58
|
-
* Parse a single node info string, extracting filename, comment, type, and
|
|
59
|
-
* other metadata.
|
|
60
|
-
*
|
|
61
|
-
* 解析单个节点的 info 字符串,提取文件名、注释、类型等属性。
|
|
62
|
-
*
|
|
63
|
-
* Recognizes the following syntax within the info string:
|
|
64
|
-
* - `++filename` — marks the node as a diff addition
|
|
65
|
-
* - `--filename` — marks the node as a diff removal
|
|
66
|
-
* - `**filename**` — highlights the node as focused
|
|
67
|
-
* - `filename # comment` — attaches an inline comment after `#`
|
|
68
|
-
* - `filename/` — treats the entry as a folder (trailing slash removed)
|
|
69
|
-
*
|
|
70
|
-
* @param info - Node description string / 节点描述字符串
|
|
71
|
-
* @returns File tree node properties excluding `children` and `level` / 文件树节点属性(不含 `children` 和 `level`)
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* parseNodeInfo('src/ # source folder')
|
|
76
|
-
* // { filename: 'src', comment: '# source folder', focus: false,
|
|
77
|
-
* // expanded: false, type: 'folder', diff: undefined }
|
|
78
|
-
*
|
|
79
|
-
* parseNodeInfo('**index.ts**')
|
|
80
|
-
* // { filename: 'index.ts', comment: '', focus: true,
|
|
81
|
-
* // expanded: true, type: 'file', diff: undefined }
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
20
|
+
|
|
84
21
|
function parseNodeInfo(info) {
|
|
85
22
|
let filename = "";
|
|
86
23
|
let comment = "";
|
|
@@ -120,33 +57,9 @@ function parseNodeInfo(info) {
|
|
|
120
57
|
diff
|
|
121
58
|
};
|
|
122
59
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
* Parse the content from the `::: file-tree` container into a node tree structure.
|
|
127
|
-
*
|
|
128
|
-
* 从 `::: file-tree` 容器中解析内容为节点树结构。
|
|
129
|
-
*
|
|
130
|
-
* Accepts indented list-style text where each entry starts with `- ` and
|
|
131
|
-
* indentation is measured in two-space increments. The first line's leading
|
|
132
|
-
* whitespace is stripped to normalize the root level. Each entry is passed
|
|
133
|
-
* to `parseNodeInfo` to extract the filename, comment, type, and other
|
|
134
|
-
* metadata.
|
|
135
|
-
*
|
|
136
|
-
* @param content - Raw file tree text content / 文件树的原始文本内容
|
|
137
|
-
* @returns File tree node array / 文件树节点数组
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```ts
|
|
141
|
-
* const content = `
|
|
142
|
-
* - src/ # source folder
|
|
143
|
-
* - index.ts
|
|
144
|
-
* - utils.ts
|
|
145
|
-
* - package.json
|
|
146
|
-
* `
|
|
147
|
-
* parseContentWithContainer(content)
|
|
148
|
-
* ```
|
|
149
|
-
*/
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
150
63
|
function parseContentWithContainer(content) {
|
|
151
64
|
const root = {
|
|
152
65
|
level: -1,
|
|
@@ -154,7 +67,7 @@ function parseContentWithContainer(content) {
|
|
|
154
67
|
};
|
|
155
68
|
const stack = [root];
|
|
156
69
|
const lines = content.trimEnd().split("\n");
|
|
157
|
-
|
|
70
|
+
|
|
158
71
|
const spaceLength = lines[0]?.match(/^\s*/)?.[0].length ?? 0;
|
|
159
72
|
for (const line of lines) {
|
|
160
73
|
const match = line.match(/^(\s*)-(.*)$/);
|
|
@@ -173,47 +86,11 @@ function parseContentWithContainer(content) {
|
|
|
173
86
|
}
|
|
174
87
|
return root.children;
|
|
175
88
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
* Regular expression for matching a single line of `tree` command output.
|
|
180
|
-
*
|
|
181
|
-
* 匹配 `tree` 命令输出的单行正则。
|
|
182
|
-
*
|
|
183
|
-
* Matches lines like:
|
|
184
|
-
* ├── filename
|
|
185
|
-
* │ ├── filename
|
|
186
|
-
* │ └── filename
|
|
187
|
-
* └── filename # optional comment
|
|
188
|
-
*
|
|
189
|
-
* - Group 1: prefix segments, each is either `│ ` (has next sibling) or ` ` (last sibling)
|
|
190
|
-
* - Group 2: branch marker, either `├── ` (non-last) or `└── ` (last)
|
|
191
|
-
* - Group 3: the filename with optional comment
|
|
192
|
-
*/
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
193
92
|
const TREE_LINE_RE = /^((?:│ {3}| {4})*)([├└]── )(.+)$/u;
|
|
194
|
-
|
|
195
|
-
* Parse `tree` command output format into a structured file tree node array.
|
|
196
|
-
*
|
|
197
|
-
* 将 `tree` 命令行输出格式解析为结构化的文件树节点数组。
|
|
198
|
-
*
|
|
199
|
-
* Converts text like:
|
|
200
|
-
* ```
|
|
201
|
-
* .
|
|
202
|
-
* ├── src
|
|
203
|
-
* │ ├── index.ts
|
|
204
|
-
* │ └── utils.ts
|
|
205
|
-
* └── package.json # project config
|
|
206
|
-
* ```
|
|
207
|
-
*
|
|
208
|
-
* into a `FileTreeNode[]` tree structure, with support for inline comments
|
|
209
|
-
* (text after `#`) on each entry. The leading root marker line (`.`) is
|
|
210
|
-
* skipped if present. Indentation depth is derived from the 4-character
|
|
211
|
-
* prefix segments, and any parent node that gains children is automatically
|
|
212
|
-
* promoted to the `folder` type.
|
|
213
|
-
*
|
|
214
|
-
* @param content - Raw `tree` command output text / `tree` 命令输出的原始文本
|
|
215
|
-
* @returns Structured file tree node array / 结构化的文件树节点数组
|
|
216
|
-
*/
|
|
93
|
+
|
|
217
94
|
function parseContentWithFence(content) {
|
|
218
95
|
const root = {
|
|
219
96
|
level: -1,
|
|
@@ -241,57 +118,11 @@ function parseContentWithFence(content) {
|
|
|
241
118
|
}
|
|
242
119
|
return root.children;
|
|
243
120
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
* markdown-it plugin for rendering file tree diagrams.
|
|
248
|
-
*
|
|
249
|
-
* 用于渲染文件树图的 markdown-it 插件。
|
|
250
|
-
*
|
|
251
|
-
* Supports two syntaxes:
|
|
252
|
-
* - Container syntax: `::: file-tree` blocks with `- filename` indented entries
|
|
253
|
-
* - Fence syntax: ` ```tree ` or ` ```file-tree ` code blocks with `tree` command output
|
|
254
|
-
*
|
|
255
|
-
* The plugin converts the parsed tree structure into nested `<VPFileTreeNode>`
|
|
256
|
-
* components wrapped by a `<VPFileTree>` container, with a URL-encoded
|
|
257
|
-
* plain-text representation for the copy button.
|
|
258
|
-
*
|
|
259
|
-
* 支持两种语法:
|
|
260
|
-
* - 容器语法:`::: file-tree` 块,其中包含以 `- 文件名` 缩进的条目
|
|
261
|
-
* - 围栏语法:` ```tree ` 或 ` ```file-tree ` 代码块,其中包含 `tree` 命令的输出
|
|
262
|
-
*
|
|
263
|
-
* 该插件将解析后的树结构转换为由 `<VPFileTree>` 容器包裹的嵌套 `<VPFileTreeNode>` 组件,并附带一个 URL 编码的纯文本表示,用于复制按钮。
|
|
264
|
-
*
|
|
265
|
-
* @example
|
|
266
|
-
* ```ts
|
|
267
|
-
* import { fileTreeMarkdownPlugin } from 'vitepress-plugin-file-tree'
|
|
268
|
-
* import { defineConfig } from 'vitepress'
|
|
269
|
-
* export default defineConfig({
|
|
270
|
-
* markdown: {
|
|
271
|
-
* config: (md) => {
|
|
272
|
-
* md.use(fileTreeMarkdownPlugin)
|
|
273
|
-
* },
|
|
274
|
-
* },
|
|
275
|
-
* })
|
|
276
|
-
* ```
|
|
277
|
-
*/
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
278
124
|
const fileTreeMarkdownPlugin = (md) => {
|
|
279
|
-
|
|
280
|
-
* Recursively render file tree nodes into nested `<VPFileTreeNode>` markup.
|
|
281
|
-
*
|
|
282
|
-
* 递归地将文件树节点渲染为嵌套的 `<VPFileTreeNode>` 标记。
|
|
283
|
-
*
|
|
284
|
-
* Empty folders automatically receive an ellipsis placeholder child so the
|
|
285
|
-
* folder icon is displayed correctly. Inline comments are rendered through
|
|
286
|
-
* `md.renderInline` and passed via the `#comment` slot.
|
|
287
|
-
*
|
|
288
|
-
* 空文件夹会自动获得一个省略号占位符子项,以便正确显示文件夹图标。
|
|
289
|
-
* 内联注释通过 `md.renderInline` 渲染,并通过 `#comment` 插槽传递。
|
|
290
|
-
*
|
|
291
|
-
* @param nodes - File tree nodes to render / 要渲染的文件树节点数组
|
|
292
|
-
* @param meta - Container-level attributes / 容器级属性
|
|
293
|
-
* @returns Rendered HTML string of nested nodes / 嵌套节点的 HTML 字符串
|
|
294
|
-
*/
|
|
125
|
+
|
|
295
126
|
const renderFileTree = (nodes, meta) => nodes.map((node) => {
|
|
296
127
|
const { level, children, filename, comment, focus, expanded, type, diff } = node;
|
|
297
128
|
if (children.length === 0 && type === "folder") children.push({
|
|
@@ -334,34 +165,9 @@ ${renderedComment}${children.length > 0 ? renderFileTree(children, meta) : ""}
|
|
|
334
165
|
return `<VPFileTree text="${encodeURIComponent(text)}">${renderFileTree(nodes, {})}</VPFileTree>`;
|
|
335
166
|
};
|
|
336
167
|
};
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
* VitePress plugin for rendering file tree diagrams in markdown.
|
|
341
|
-
*
|
|
342
|
-
* VitePress 插件,用于在 markdown 中渲染文件树图。
|
|
343
|
-
*
|
|
344
|
-
* Registers the `fileTreeMarkdownPlugin` with markdown-it to parse both
|
|
345
|
-
* container syntax (`::: file-tree`) and fence syntax (` ```tree ` or
|
|
346
|
-
* ` ```file-tree `) into interactive collapsible file trees. On the client
|
|
347
|
-
* side, the `VPFileTree` and `VPFileTreeNode` Vue components are injected
|
|
348
|
-
* globally via `virtual:enhance-app`.
|
|
349
|
-
*
|
|
350
|
-
* The rendered tree supports inline comments, focus highlights, diff markers
|
|
351
|
-
* for added or removed entries, and a copy button that outputs the plain-text
|
|
352
|
-
* `tree` command representation.
|
|
353
|
-
*
|
|
354
|
-
* @example
|
|
355
|
-
* `.vitepress/config.ts`
|
|
356
|
-
* ```ts
|
|
357
|
-
* import { defineConfig } from 'vitepress-tuck'
|
|
358
|
-
* import fileTree from 'vitepress-plugin-file-tree'
|
|
359
|
-
*
|
|
360
|
-
* export default defineConfig({
|
|
361
|
-
* plugins: [fileTree()],
|
|
362
|
-
* })
|
|
363
|
-
* ```
|
|
364
|
-
*/
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
365
171
|
const fileTree = definePlugin(() => ({
|
|
366
172
|
name: "vitepress-plugin-file-tree",
|
|
367
173
|
componentResolver: ["VPFileTree", "VPFileTreeNode"],
|
|
@@ -373,16 +179,9 @@ const fileTree = definePlugin(() => ({
|
|
|
373
179
|
ssr: { noExternal: ["vitepress-plugin-file-tree"] }
|
|
374
180
|
}
|
|
375
181
|
}));
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
* Entry point for the `vitepress-plugin-file-tree` package.
|
|
380
|
-
*
|
|
381
|
-
* `vitepress-plugin-file-tree` 插件的入口模块。
|
|
382
|
-
*
|
|
383
|
-
* Re-exports all node-side utilities, the markdown-it plugin, parsing helpers,
|
|
384
|
-
* and the main `fileTree` plugin definition as the default export.
|
|
385
|
-
*/
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
386
185
|
var node_default = fileTree;
|
|
387
|
-
|
|
186
|
+
|
|
388
187
|
export { node_default as default, fileTree, fileTreeMarkdownPlugin, fileTreeToCMDText, parseContentWithContainer, parseContentWithFence, parseNodeInfo };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitepress-plugin-file-tree",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"description": "Render file tree structure in your VitePress site.",
|
|
6
6
|
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo/)",
|
|
7
7
|
"license": "MIT",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"vue": "^3.5.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@pengzhanbo/utils": "^3.7.
|
|
40
|
+
"@pengzhanbo/utils": "^3.7.4",
|
|
41
41
|
"@vueuse/core": "^14.3.0",
|
|
42
|
-
"vitepress-plugin-toolkit": "0.
|
|
43
|
-
"vitepress-tuck": "0.
|
|
42
|
+
"vitepress-plugin-toolkit": "0.11.0",
|
|
43
|
+
"vitepress-tuck": "0.11.0"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public",
|