rspress-plugin-file-tree 0.2.0 → 0.4.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/parser.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  type TreeItem = {
2
2
  type: 'file' | 'directory';
3
3
  name: string;
4
+ extra?: string;
4
5
  files?: TreeItem[];
5
6
  };
6
7
  export declare function parseInput(input: string): TreeItem[];
package/dist/parser.js CHANGED
@@ -5,7 +5,7 @@ function countLeadingSpaces(line) {
5
5
  return matches[0].length;
6
6
  }
7
7
  export function parseInput(input) {
8
- var _a;
8
+ var _a, _b;
9
9
  const lines = input.split('\n').filter((line) => line.trim());
10
10
  const tree = [];
11
11
  const stack = [];
@@ -14,11 +14,14 @@ export function parseInput(input) {
14
14
  if (line === '.')
15
15
  continue;
16
16
  const level = countLeadingSpaces(line);
17
- const name = line.trim().split(' ').slice(-1)[0];
17
+ const normalizedLine = line.split('').slice(-1)[0].trimStart();
18
+ const [_, name, extra = ''] = (_a = normalizedLine.match(/^(.*?)(?:\s*\/\/\s*(.*))?$/)) !== null && _a !== void 0 ? _a : [];
18
19
  const nextLine = lines[i + 1] || '';
19
20
  const nextLineLevel = countLeadingSpaces(nextLine);
20
21
  const type = nextLineLevel > level ? 'directory' : 'file';
21
- const item = type === 'directory' ? { type, name, files: [] } : { type, name };
22
+ const item = type === 'directory'
23
+ ? { type, name, files: [], extra }
24
+ : { type, name, extra };
22
25
  while (stack.length > 0 && stack[stack.length - 1].level >= level) {
23
26
  stack.pop();
24
27
  }
@@ -27,7 +30,7 @@ export function parseInput(input) {
27
30
  }
28
31
  else {
29
32
  const parentItem = stack[stack.length - 1].item;
30
- (_a = parentItem.files) === null || _a === void 0 ? void 0 : _a.push(item);
33
+ (_b = parentItem.files) === null || _b === void 0 ? void 0 : _b.push(item);
31
34
  }
32
35
  if (item.type === 'directory') {
33
36
  stack.push({ level, item });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rspress-plugin-file-tree",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Rspress plugin that add support for file tree component.",
5
5
  "files": [
6
6
  "dist",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@rspress/shared": "^1.17.1",
32
- "rspress-plugin-devkit": "^0.2.0"
32
+ "rspress-plugin-devkit": "^0.3.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/node": "^20.12.5",