Skip to content

Commit 4bee650

Browse files
authored
Merge pull request #25 from ran-codes/feature/20-qmd-headers-support
Feature/20 qmd headers support
2 parents 8a10fc8 + ec2d959 commit 4bee650

4 files changed

Lines changed: 373 additions & 22 deletions

File tree

src/test/jsx-comments.test.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ function MyComponent() {
2323
);
2424
}
2525
`;
26-
27-
const sections = findSections(text);
26+
const sections = findSections(text, 'jsx');
2827
assert.strictEqual(sections.length, 3);
2928
assert.strictEqual(sections[0].name, 'Main Component');
3029
assert.strictEqual(sections[0].depth, 1);
@@ -62,29 +61,23 @@ function Layout() {
6261
);
6362
}
6463
`;
65-
66-
const sections = findSections(text);
64+
const sections = findSections(text, 'jsx');
6765
assert.strictEqual(sections.length, 5);
68-
6966
// Main Layout (depth 1)
7067
assert.strictEqual(sections[0].name, 'Main Layout');
7168
assert.strictEqual(sections[0].depth, 1);
72-
7369
// Navigation (depth 2)
7470
assert.strictEqual(sections[1].name, 'Navigation');
7571
assert.strictEqual(sections[1].depth, 2);
7672
assert.strictEqual(sections[1].parentName, sections[0].uniqueId);
77-
7873
// Menu Items (depth 3)
7974
assert.strictEqual(sections[2].name, 'Menu Items');
8075
assert.strictEqual(sections[2].depth, 3);
8176
assert.strictEqual(sections[2].parentName, sections[1].uniqueId);
82-
8377
// User Actions (depth 3)
8478
assert.strictEqual(sections[3].name, 'User Actions');
8579
assert.strictEqual(sections[3].depth, 3);
8680
assert.strictEqual(sections[3].parentName, sections[1].uniqueId);
87-
8881
// Main Content (depth 2)
8982
assert.strictEqual(sections[4].name, 'Main Content');
9083
assert.strictEqual(sections[4].depth, 2);
@@ -98,8 +91,7 @@ function Component() {
9891
return <div></div>;
9992
}
10093
`;
101-
102-
const sections = findSections(text);
94+
const sections = findSections(text, 'jsx');
10395
assert.strictEqual(sections.length, 1);
10496
assert.strictEqual(sections[0].name, 'Spaced Section');
10597
assert.strictEqual(sections[0].depth, 1);
@@ -113,8 +105,7 @@ function Component() {
113105
return <div></div>;
114106
}
115107
`;
116-
117-
const sections = findSections(text);
108+
const sections = findSections(text, 'jsx');
118109
assert.strictEqual(sections.length, 1);
119110
assert.strictEqual(sections[0].name, 'Valid Section');
120111
});
@@ -129,8 +120,7 @@ function Component() {
129120
return <div></div>;
130121
}
131122
`;
132-
133-
const sections = findSections(text);
123+
const sections = findSections(text, 'jsx');
134124
assert.strictEqual(sections.length, 1);
135125
assert.strictEqual(sections[0].name, 'Proper Section');
136126
});
@@ -150,8 +140,7 @@ function Component() {
150140
);
151141
}
152142
`;
153-
154-
const sections = findSections(text);
143+
const sections = findSections(text, 'jsx');
155144
assert.strictEqual(sections.length, 3);
156145
assert.strictEqual(sections[0].name, 'Traditional JS Comment');
157146
assert.strictEqual(sections[0].depth, 1);
@@ -185,8 +174,7 @@ const MyComponent: React.FC<Props> = ({ title }) => {
185174
);
186175
};
187176
`;
188-
189-
const sections = findSections(text);
177+
const sections = findSections(text, 'tsx');
190178
assert.strictEqual(sections.length, 3);
191179
assert.strictEqual(sections[0].name, 'Component Definition');
192180
assert.strictEqual(sections[0].depth, 1);

src/test/md-comments.test.ts

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
import * as assert from 'assert';
2+
import { findSections } from '../utils/findSections';
3+
4+
suite('Markdown Header Section Detection', () => {
5+
test('should detect realistic markdown headers as sections', () => {
6+
const text = `
7+
# 1. Project Documentation
8+
This is a test markdown file for the Code Organizer extension.
9+
code
10+
code
11+
code
12+
code
13+
code
14+
code
15+
code
16+
code
17+
code
18+
code
19+
code
20+
code
21+
code
22+
code
23+
code
24+
code
25+
code
26+
code
27+
code
28+
code
29+
30+
## 1.1 Installation
31+
Install the extension from VS Code marketplace.
32+
code
33+
code
34+
code
35+
code
36+
code
37+
code
38+
code
39+
code
40+
code
41+
code
42+
code
43+
code
44+
code
45+
code
46+
code
47+
code
48+
code
49+
code
50+
code
51+
code
52+
53+
### 1.1.1 Requirements
54+
- VS Code 1.102.0 or higher
55+
- No additional dependencies
56+
code
57+
code
58+
code
59+
code
60+
code
61+
code
62+
code
63+
code
64+
code
65+
code
66+
code
67+
code
68+
code
69+
code
70+
code
71+
code
72+
code
73+
code
74+
code
75+
code
76+
77+
## 1.2 Usage
78+
Create sections using hash comments followed by 4+ dashes.
79+
code
80+
code
81+
code
82+
code
83+
code
84+
code
85+
code
86+
code
87+
code
88+
code
89+
code
90+
code
91+
code
92+
code
93+
code
94+
code
95+
code
96+
code
97+
code
98+
code
99+
100+
### 1.2.1 Basic Syntax
101+
# Section Name
102+
code
103+
code
104+
code
105+
code
106+
code
107+
code
108+
code
109+
code
110+
code
111+
code
112+
code
113+
code
114+
code
115+
code
116+
code
117+
code
118+
code
119+
code
120+
code
121+
code
122+
123+
### 1.2.2 Nested Sections
124+
Use multiple hash symbols for nesting:
125+
# Main Section
126+
## Sub Section
127+
### Sub-Sub Section
128+
code
129+
code
130+
code
131+
code
132+
code
133+
code
134+
code
135+
code
136+
code
137+
code
138+
code
139+
code
140+
code
141+
code
142+
code
143+
code
144+
code
145+
code
146+
code
147+
code
148+
code
149+
code
150+
code
151+
code
152+
code
153+
code
154+
code
155+
156+
# 2. Examples
157+
Here are some examples of how to use the extension.
158+
code
159+
code
160+
code
161+
code
162+
code
163+
code
164+
code
165+
code
166+
code
167+
code
168+
code
169+
code
170+
code
171+
code
172+
code
173+
174+
## 2.1 Code Examples
175+
The extension works with any file type that supports hash comments.
176+
code
177+
code
178+
code
179+
code
180+
code
181+
code
182+
code
183+
code
184+
code
185+
code
186+
code
187+
code
188+
code
189+
code
190+
code
191+
`;
192+
const sections = findSections(text, 'md');
193+
assert.strictEqual(sections.length, 12);
194+
assert.strictEqual(sections[0].name, '1. Project Documentation');
195+
assert.strictEqual(sections[0].depth, 1);
196+
assert.strictEqual(sections[1].name, '1.1 Installation');
197+
assert.strictEqual(sections[1].depth, 2);
198+
assert.strictEqual(sections[2].name, '1.1.1 Requirements');
199+
assert.strictEqual(sections[2].depth, 3);
200+
assert.strictEqual(sections[3].name, '1.2 Usage');
201+
assert.strictEqual(sections[3].depth, 2);
202+
assert.strictEqual(sections[4].name, '1.2.1 Basic Syntax');
203+
assert.strictEqual(sections[4].depth, 3);
204+
assert.strictEqual(sections[5].name, 'Section Name');
205+
assert.strictEqual(sections[5].depth, 1);
206+
assert.strictEqual(sections[6].name, '1.2.2 Nested Sections');
207+
assert.strictEqual(sections[6].depth, 3);
208+
assert.strictEqual(sections[7].name, 'Main Section');
209+
assert.strictEqual(sections[7].depth, 1);
210+
assert.strictEqual(sections[8].name, 'Sub Section');
211+
assert.strictEqual(sections[8].depth, 2);
212+
assert.strictEqual(sections[9].name, 'Sub-Sub Section');
213+
assert.strictEqual(sections[9].depth, 3);
214+
assert.strictEqual(sections[10].name, '2. Examples');
215+
assert.strictEqual(sections[10].depth, 1);
216+
assert.strictEqual(sections[11].name, '2.1 Code Examples');
217+
assert.strictEqual(sections[11].depth, 2);
218+
});
219+
});

0 commit comments

Comments
 (0)