From 2780abd7824ad670e2f482ca90c24fa53fd110fe Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Fri, 13 Feb 2026 01:16:47 +0800 Subject: [PATCH] feat(plugin-md-power): add copy button for file-tree container, close #835 (#837) * feat(plugin-md-power): add copy button for file-tree container, close #835 * chore: tweak --- .../__snapshots__/fileTreePlugin.spec.ts.snap | 98 +++++++++++--- .../__test__/fileTreePlugin.spec.ts | 4 +- .../src/client/components/FileTreeNode.vue | 9 ++ .../src/client/components/VPCopyButton.vue | 23 ++++ .../src/node/container/createContainer.ts | 2 - .../src/node/container/fileTree.ts | 46 +++++-- .../src/node/container/index.ts | 7 +- .../plugin-md-power/src/node/locales/de.ts | 4 + .../plugin-md-power/src/node/locales/en.ts | 4 + .../plugin-md-power/src/node/locales/fr.ts | 4 + .../plugin-md-power/src/node/locales/ja.ts | 4 + .../plugin-md-power/src/node/locales/ko.ts | 4 + .../plugin-md-power/src/node/locales/ru.ts | 4 + .../plugin-md-power/src/node/locales/zh-tw.ts | 4 + .../plugin-md-power/src/node/locales/zh.ts | 4 + plugins/plugin-md-power/src/node/plugin.ts | 125 ++++++++++-------- .../src/node/prepareConfigFile.ts | 3 + .../plugin-md-power/src/node/provideData.ts | 32 +---- .../src/node/utils/findLocales.ts | 15 +++ plugins/plugin-md-power/src/shared/index.ts | 1 + plugins/plugin-md-power/src/shared/locale.ts | 6 + 21 files changed, 284 insertions(+), 119 deletions(-) create mode 100644 plugins/plugin-md-power/src/client/components/VPCopyButton.vue create mode 100644 plugins/plugin-md-power/src/node/utils/findLocales.ts diff --git a/plugins/plugin-md-power/__test__/__snapshots__/fileTreePlugin.spec.ts.snap b/plugins/plugin-md-power/__test__/__snapshots__/fileTreePlugin.spec.ts.snap index 42d0caaf..b76ed869 100644 --- a/plugins/plugin-md-power/__test__/__snapshots__/fileTreePlugin.spec.ts.snap +++ b/plugins/plugin-md-power/__test__/__snapshots__/fileTreePlugin.spec.ts.snap @@ -6,17 +6,32 @@ exports[`fileTree > parseFileTreeRawContent > should work 1`] = ` "children": [ { "children": [], - "info": "README.md", + "comment": "", + "diff": undefined, + "expanded": true, + "filename": "README.md", + "focus": false, "level": 1, + "type": "file", }, { "children": [], - "info": "foo.md", + "comment": "", + "diff": undefined, + "expanded": true, + "filename": "foo.md", + "focus": false, "level": 1, + "type": "file", }, ], - "info": "docs", + "comment": "", + "diff": undefined, + "expanded": true, + "filename": "docs", + "focus": false, "level": 0, + "type": "file", }, { "children": [ @@ -26,52 +41,97 @@ exports[`fileTree > parseFileTreeRawContent > should work 1`] = ` "children": [ { "children": [], - "info": "**Navbar.vue**", + "comment": "", + "diff": undefined, + "expanded": true, + "filename": "Navbar.vue", + "focus": true, "level": 3, + "type": "file", }, ], - "info": "components", + "comment": "", + "diff": undefined, + "expanded": true, + "filename": "components", + "focus": false, "level": 2, + "type": "file", }, { "children": [], - "info": "index.ts # comment", + "comment": "# comment", + "diff": undefined, + "expanded": true, + "filename": "index.ts", + "focus": false, "level": 2, + "type": "file", }, ], - "info": "client", + "comment": "", + "diff": undefined, + "expanded": true, + "filename": "client", + "focus": false, "level": 1, + "type": "file", }, { "children": [ { "children": [], - "info": "index.ts", + "comment": "", + "diff": undefined, + "expanded": true, + "filename": "index.ts", + "focus": false, "level": 2, + "type": "file", }, ], - "info": "node", + "comment": "", + "diff": undefined, + "expanded": true, + "filename": "node", + "focus": false, "level": 1, + "type": "file", }, ], - "info": "src", + "comment": "", + "diff": undefined, + "expanded": true, + "filename": "src", + "focus": false, "level": 0, + "type": "file", }, { "children": [], - "info": ".gitignore", + "comment": "", + "diff": undefined, + "expanded": true, + "filename": ".gitignore", + "focus": false, "level": 0, + "type": "file", }, { "children": [], - "info": "package.json", + "comment": "", + "diff": undefined, + "expanded": true, + "filename": "package.json", + "focus": false, "level": 0, + "type": "file", }, ] `; exports[`fileTreePlugin > should work with default options 1`] = ` -"
+"
@@ -102,7 +162,7 @@ exports[`fileTreePlugin > should work with default options 1`] = `
-

files

+

files

@@ -122,7 +182,7 @@ exports[`fileTreePlugin > should work with default options 1`] = `
-
+
@@ -136,7 +196,7 @@ exports[`fileTreePlugin > should work with default options 1`] = `
-
+
@@ -144,7 +204,7 @@ exports[`fileTreePlugin > should work with default options 1`] = `
-
+
@@ -158,7 +218,7 @@ exports[`fileTreePlugin > should work with default options 1`] = `
-
+
" `; @@ -166,7 +226,7 @@ exports[`fileTreePlugin > should work with nesting content 1`] = ` "
  • item1

    -
    +
    diff --git a/plugins/plugin-md-power/__test__/fileTreePlugin.spec.ts b/plugins/plugin-md-power/__test__/fileTreePlugin.spec.ts index 74b6701a..54325d46 100644 --- a/plugins/plugin-md-power/__test__/fileTreePlugin.spec.ts +++ b/plugins/plugin-md-power/__test__/fileTreePlugin.spec.ts @@ -56,7 +56,9 @@ describe('fileTree > parseFileTreeNodeInfo', () => { }) function createMarkdown(options?: FileTreeOptions) { - return new MarkdownIt().use(fileTreePlugin, options) + const md = new MarkdownIt() + fileTreePlugin(md, options, {}) + return md } describe('fileTreePlugin', () => { diff --git a/plugins/plugin-md-power/src/client/components/FileTreeNode.vue b/plugins/plugin-md-power/src/client/components/FileTreeNode.vue index 60b3c5e3..5c8a8edd 100644 --- a/plugins/plugin-md-power/src/client/components/FileTreeNode.vue +++ b/plugins/plugin-md-power/src/client/components/FileTreeNode.vue @@ -68,6 +68,7 @@ function toggle(ev: MouseEvent) {