rspress-plugin-file-tree 1.0.2 → 1.0.3

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.
@@ -70,6 +70,7 @@
70
70
  white-space: nowrap;
71
71
  text-overflow: ellipsis;
72
72
  margin-left: 8px;
73
+ padding: 0 4px;
73
74
  font-style: italic;
74
75
  overflow: hidden;
75
76
  }
package/dist/index.js CHANGED
@@ -3,10 +3,11 @@ import { RemarkCodeBlockToGlobalComponentPluginFactory } from "rspress-plugin-de
3
3
  function parseTreeContent(content) {
4
4
  let lines = content.split('\n').filter((line)=>line.trim());
5
5
  if (lines.length > 0 && '.' === lines[0].trim()) lines = lines.slice(1);
6
+ const indentSize = detectIndentSize(lines);
6
7
  const nodes = [];
7
8
  const stack = [];
8
9
  for (const line of lines){
9
- const indent = calculateIndent(line);
10
+ const indent = calculateIndent(line, indentSize);
10
11
  const fullName = extractName(line);
11
12
  const { name, comment } = extractNameAndComment(fullName);
12
13
  if (!name) continue;
@@ -31,30 +32,43 @@ function parseTreeContent(content) {
31
32
  raw: content
32
33
  };
33
34
  }
34
- function calculateIndent(line) {
35
+ function detectIndentSize(lines) {
36
+ for (const line of lines){
37
+ const match = line.match(/^( +)[├└]/);
38
+ if (match) {
39
+ const spaceCount = match[1].length;
40
+ if (2 === spaceCount) return 2;
41
+ }
42
+ if (/│ [├└]/.test(line)) return 2;
43
+ }
44
+ return 4;
45
+ }
46
+ function calculateIndent(line, indentSize) {
35
47
  let indent = 0;
36
48
  let i = 0;
37
49
  while(i < line.length){
38
50
  const char = line[i];
39
- if ('│' === char && '│ ' === line.substring(i, i + 4)) {
51
+ if (4 === indentSize && '│' === char && '│ ' === line.substring(i, i + 4)) {
40
52
  indent++;
41
53
  i += 4;
42
54
  continue;
43
55
  }
44
- if ('│' === char && ' ' === line[i + 1]) {
56
+ if (2 === indentSize && '│' === char && ' ' === line[i + 1]) {
45
57
  indent++;
46
58
  i += 2;
47
59
  continue;
48
60
  }
49
- if (' ' === line.substring(i, i + 4)) {
50
- indent++;
51
- i += 4;
52
- continue;
53
- }
54
- if (' ' === line.substring(i, i + 2)) {
55
- indent++;
56
- i += 2;
57
- continue;
61
+ if (' ' === char) {
62
+ if (2 === indentSize && ' ' === line.substring(i, i + 2)) {
63
+ indent++;
64
+ i += 2;
65
+ continue;
66
+ }
67
+ if (4 === indentSize && ' ' === line.substring(i, i + 4)) {
68
+ indent++;
69
+ i += 4;
70
+ continue;
71
+ }
58
72
  }
59
73
  if ('├' === char || '└' === char) {
60
74
  if ('├──' === line.substring(i, i + 3) || '└──' === line.substring(i, i + 3)) indent++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rspress-plugin-file-tree",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Rspress plugin that add support for file tree component.",
5
5
  "files": [
6
6
  "dist"