Skip to content

Commit 4c7ee97

Browse files
committed
feat: multiline comments
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 9392f89 commit 4c7ee97

15 files changed

+141
-81
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ Options for parsing markdown with respect for comment delimiters (TypeScript typ
377377
#### Properties
378378

379379
- `code` (`boolean`, optional) &mdash; parse markdown value as fenced code
380+
- `multiline` (`boolean`, optional) &mdash; parse multiline comments
380381
- `position` ([`Position`][docast-position]) &mdash; position of markdown value
381382

382383
### `Transform`

src/__snapshots__/util.integration.snap

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
exports[`integration:fromDocs > non-empty document > document sample 0 1`] = `
44
root[2]
55
├─0 comment[2] (1:1-4:4, 0-83)
6-
│ │ code: null
76
│ ├─0 blockTag<@file>[1] (2:4-2:38, 7-41)
87
│ │ └─0 text "Fixtures - validateURLString" (2:10-2:38, 13-41)
98
│ └─1 blockTag<@module>[1] (3:4-3:38, 45-79)
109
│ └─0 text "fixtures/validateURLString" (3:12-3:38, 53-79)
1110
└─1 comment[7] (10:1-25:4, 250-800)
12-
│ code: null
1311
├─0 description[7] (11:4-15:65, 257-461)
1412
│ ├─0 paragraph[5] (11:4-11:68, 257-321)
1513
│ │ ├─0 text "Checks if " (11:4-11:14, 257-267)
@@ -67,13 +65,11 @@ root[2]
6765
exports[`integration:fromDocs > non-empty document > document sample 1 1`] = `
6866
root[4]
6967
├─0 comment[2] (1:1-4:4, 0-73)
70-
│ │ code: null
7168
│ ├─0 blockTag<@file>[1] (2:4-2:33, 7-36)
7269
│ │ └─0 text "Fixtures - detectSyntax" (2:10-2:33, 13-36)
7370
│ └─1 blockTag<@module>[1] (3:4-3:33, 40-69)
7471
│ └─0 text "fixtures/detectSyntax" (3:12-3:33, 48-69)
7572
├─1 comment[6] (8:1-27:4, 144-603)
76-
│ │ code: null
7773
│ ├─0 description[4] (9:4-11:32, 151-263)
7874
│ │ ├─0 paragraph[3] (9:4-9:81, 151-228)
7975
│ │ │ ├─0 text "Detects if " (9:4-9:15, 151-162)
@@ -99,15 +95,13 @@ root[4]
9995
│ ├─0 typeExpression "{\\ncjs: boolean;\\nesm: boolean;\\nmixed: boolean\\n}" (22:12-26:6, 519-582)
10096
│ └─1 text "Detection result" (26:7-26:23, 583-599)
10197
├─2 comment[2] (31:3-35:6, 699-767)
102-
│ │ code: null
10398
│ ├─0 description[1] (32:6-32:28, 708-730)
10499
│ │ └─0 paragraph[1] (32:6-32:28, 708-730)
105100
│ │ └─0 text "CommonJS syntax check." (32:6-32:28, 708-730)
106101
│ └─1 blockTag<@const>[2] (34:6-34:26, 741-761)
107102
│ ├─0 typeExpression "boolean" (34:13-34:22, 748-757)
108103
│ └─1 text "cjs" (34:23-34:26, 758-761)
109104
└─3 comment[2] (38:3-42:6, 813-876)
110-
│ code: null
111105
├─0 description[1] (39:6-39:23, 822-839)
112106
│ └─0 paragraph[1] (39:6-39:23, 822-839)
113107
│ └─0 text "ESM syntax check." (39:6-39:23, 822-839)
@@ -119,13 +113,11 @@ root[4]
119113
exports[`integration:fromDocs > non-empty document > document sample 2 1`] = `
120114
root[2]
121115
├─0 comment[2] (1:1-4:4, 0-87)
122-
│ │ code: null
123116
│ ├─0 blockTag<@file>[1] (2:4-2:40, 7-43)
124117
│ │ └─0 text "Fixtures - toRelativeSpecifier" (2:10-2:40, 13-43)
125118
│ └─1 blockTag<@module>[1] (3:4-3:40, 47-83)
126119
│ └─0 text "fixtures/toRelativeSpecifier" (3:12-3:40, 55-83)
127120
└─1 comment[7] (12:1-28:4, 340-923)
128-
│ code: null
129121
├─0 description[4] (13:4-18:7, 347-521)
130122
│ ├─0 paragraph[3] (13:4-13:51, 347-394)
131123
│ │ ├─0 text "Converts " (13:4-13:13, 347-356)
@@ -165,17 +157,15 @@ root[2]
165157
`;
166158
167159
exports[`integration:fromDocs > non-empty document > document sample 3 1`] = `
168-
root[7]
160+
root[9]
169161
├─0 comment[3] (1:1-5:4, 0-126)
170-
│ │ code: null
171162
│ ├─0 blockTag<@file>[1] (2:4-2:30, 7-33)
172163
│ │ └─0 text "Fixtures - dblLinear" (2:10-2:30, 13-33)
173164
│ ├─1 blockTag<@module>[1] (3:4-3:30, 37-63)
174165
│ │ └─0 text "fixtures/dblLinear" (3:12-3:30, 45-63)
175166
│ └─2 blockTag<@see>[1] (4:4-4:59, 67-122)
176167
│ └─0 text "https://codewars.com/kata/5672682212c8ecf83e000050" (4:9-4:59, 72-122)
177168
├─1 comment[8] (7:1-36:4, 128-844)
178-
│ │ code: null
179169
│ ├─0 description[7] (8:4-21:68, 135-553)
180170
│ │ ├─0 paragraph[5] (8:4-8:60, 135-191)
181171
│ │ │ ├─0 text "Consider a sequence " (8:4-8:24, 135-155)
@@ -286,54 +276,54 @@ root[7]
286276
│ ├─1 text "Element at " (35:30-35:41, 823-834)
287277
│ └─2 inlineCode "u(n)" (35:41-35:47, 834-840)
288278
├─2 comment[1] (38:3-38:40, 902-939)
289-
│ │ code: null
290279
│ └─0 blockTag<@const>[2] (38:7-38:37, 906-936)
291280
│ ├─0 typeExpression "number[]" (38:14-38:24, 913-923)
292281
│ └─1 text "u - Sequence" (38:25-38:37, 924-936)
293282
├─3 comment[1] (41:3-41:75, 969-1041)
294-
│ │ code: null
295283
│ └─0 blockTag<@var>[4] (41:7-41:72, 973-1038)
296284
│ ├─0 typeExpression "number" (41:12-41:20, 978-986)
297285
│ ├─1 text "j - Index of x in " (41:21-41:39, 987-1005)
298286
│ ├─2 inlineTag<@linkcode> "u" (41:39-41:52, 1005-1018)
299287
│ └─3 text " used to calculate y" (41:52-41:72, 1018-1038)
300288
├─4 comment[1] (44:3-44:75, 1065-1137)
301-
│ │ code: null
302289
│ └─0 blockTag<@var>[4] (44:7-44:72, 1069-1134)
303290
│ ├─0 typeExpression "number" (44:12-44:20, 1074-1082)
304291
│ ├─1 text "k - Index of x in " (44:21-44:39, 1083-1101)
305292
│ ├─2 inlineTag<@linkcode> "u" (44:39-44:52, 1101-1114)
306293
│ └─3 text " used to calculate z" (44:52-44:72, 1114-1134)
307-
├─5 comment[1] (51:5-51:35, 1253-1283)
308-
│ │ code: null
294+
├─5 comment[1] (47:3-49:6, 1161-1215)
295+
│ └─0 description[1] (48:6-48:46, 1169-1209)
296+
│ └─0 paragraph[1] (48:6-48:46, 1169-1209)
297+
│ └─0 text "build sequence up to index n (inclusive)" (48:6-48:46, 1169-1209)
298+
├─6 comment[1] (51:5-51:35, 1253-1283)
309299
│ └─0 blockTag<@const>[3] (51:9-51:32, 1257-1280)
310300
│ ├─0 typeExpression "number" (51:16-51:24, 1264-1272)
311301
│ ├─1 text "y - " (51:25-51:29, 1273-1277)
312302
│ └─2 inlineCode "y" (51:29-51:32, 1277-1280)
313-
└─6 comment[1] (54:5-54:35, 1325-1355)
314-
│ code: null
315-
└─0 blockTag<@const>[3] (54:9-54:32, 1329-1352)
316-
├─0 typeExpression "number" (54:16-54:24, 1336-1344)
317-
├─1 text "z - " (54:25-54:29, 1345-1349)
318-
└─2 inlineCode "z" (54:29-54:32, 1349-1352)
303+
├─7 comment[1] (54:5-54:35, 1325-1355)
304+
│ └─0 blockTag<@const>[3] (54:9-54:32, 1329-1352)
305+
│ ├─0 typeExpression "number" (54:16-54:24, 1336-1344)
306+
│ ├─1 text "z - " (54:25-54:29, 1345-1349)
307+
│ └─2 inlineCode "z" (54:29-54:32, 1349-1352)
308+
└─8 comment[1] (57:5-57:57, 1397-1449)
309+
└─0 description[1] (57:8-57:54, 1400-1446)
310+
└─0 paragraph[1] (57:8-57:54, 1400-1446)
311+
└─0 text "set sequence value to smallest value in [y, z]" (57:8-57:54, 1400-1446)
319312
`;
320313
321314
exports[`integration:fromDocs > non-empty document > document sample 4 1`] = `
322315
root[14]
323316
├─0 comment[2] (1:1-4:4, 0-61)
324-
│ │ code: null
325317
│ ├─0 blockTag<@file>[1] (2:4-2:27, 7-30)
326318
│ │ └─0 text "Fixtures - Reader" (2:10-2:27, 13-30)
327319
│ └─1 blockTag<@module>[1] (3:4-3:27, 34-57)
328320
│ └─0 text "fixtures/Reader" (3:12-3:27, 42-57)
329321
├─1 comment[2] (12:1-16:4, 304-351)
330-
│ │ code: null
331322
│ ├─0 description[1] (13:4-13:27, 311-334)
332323
│ │ └─0 paragraph[1] (13:4-13:27, 311-334)
333324
│ │ └─0 text "Source document reader." (13:4-13:27, 311-334)
334325
│ └─1 blockTag<@class>[0] (15:4-15:10, 341-347)
335326
├─2 comment[5] (18:3-25:6, 369-479)
336-
│ │ code: null
337327
│ ├─0 description[1] (19:6-19:22, 378-394)
338328
│ │ └─0 paragraph[1] (19:6-19:22, 378-394)
339329
│ │ └─0 text "Source document." (19:6-19:22, 378-394)
@@ -344,7 +334,6 @@ root[14]
344334
│ ├─0 typeExpression "string" (24:14-24:22, 456-464)
345335
│ └─1 text "document" (24:23-24:31, 465-473)
346336
├─3 comment[5] (28:3-36:6, 518-726)
347-
│ │ code: null
348337
│ ├─0 description[1] (29:6-30:36, 527-637)
349338
│ │ └─0 paragraph[3] (29:6-30:36, 527-637)
350339
│ │ ├─0 text "List, where each index is a line number (" (29:6-29:47, 527-568)
@@ -357,7 +346,6 @@ root[14]
357346
│ ├─0 typeExpression "number[]" (35:14-35:24, 702-712)
358347
│ └─1 text "indices" (35:25-35:32, 713-720)
359348
├─4 comment[4] (39:3-45:6, 769-892)
360-
│ │ code: null
361349
│ ├─0 description[1] (40:6-40:47, 778-819)
362350
│ │ └─0 paragraph[3] (40:6-40:47, 778-819)
363351
│ │ ├─0 text "Current position in " (40:6-40:26, 778-798)
@@ -369,7 +357,6 @@ root[14]
369357
│ ├─0 typeExpression "number" (44:14-44:22, 869-877)
370358
│ └─1 text "position" (44:23-44:31, 878-886)
371359
├─5 comment[3] (48:3-54:6, 925-1076)
372-
│ │ code: null
373360
│ ├─0 description[1] (49:6-49:42, 934-970)
374361
│ │ └─0 paragraph[1] (49:6-49:42, 934-970)
375362
│ │ └─0 text "Create a new source document reader." (49:6-49:42, 934-970)
@@ -379,7 +366,6 @@ root[14]
379366
│ ├─0 typeExpression "VFile | string" (53:13-53:29, 1021-1037)
380367
│ └─1 text "source - Source document or file" (53:30-53:62, 1038-1070)
381368
├─6 comment[5] (61:3-75:6, 1266-1522)
382-
│ │ code: null
383369
│ ├─0 description[1] (62:6-62:56, 1275-1325)
384370
│ │ └─0 paragraph[1] (62:6-62:56, 1275-1325)
385371
│ │ └─0 text "Check if the reader is at the end of the document." (62:6-62:56, 1275-1325)
@@ -394,7 +380,6 @@ root[14]
394380
│ ├─1 inlineCode "true" (74:24-74:30, 1488-1494)
395381
│ └─2 text " if at end of document" (74:30-74:52, 1494-1516)
396382
├─7 comment[4] (80:3-87:6, 1606-1751)
397-
│ │ code: null
398383
│ ├─0 description[1] (81:6-81:47, 1615-1656)
399384
│ │ └─0 paragraph[1] (81:6-81:47, 1615-1656)
400385
│ │ └─0 text "Get the current position in the document." (81:6-81:47, 1615-1656)
@@ -404,7 +389,6 @@ root[14]
404389
│ ├─0 typeExpression "number" (86:14-86:22, 1708-1716)
405390
│ └─1 text "Current position in document" (86:23-86:51, 1717-1745)
406391
├─8 comment[6] (92:3-104:6, 1815-2222)
407-
│ │ code: null
408392
│ ├─0 description[1] (93:6-94:75, 1824-1972)
409393
│ │ └─0 paragraph[5] (93:6-94:75, 1824-1972)
410394
│ │ ├─0 text "Get the next " (93:6-93:19, 1824-1837)
@@ -426,7 +410,6 @@ root[14]
426410
│ ├─1 text "Peeked character code or " (103:21-103:46, 2185-2210)
427411
│ └─2 inlineCode "null" (103:46-103:52, 2210-2216)
428412
├─9 comment[7] (110:3-138:6, 2388-3460)
429-
│ │ code: null
430413
│ ├─0 description[12] (111:6-128:42, 2397-3216)
431414
│ │ ├─0 paragraph[5] (111:6-111:53, 2397-2444)
432415
│ │ │ ├─0 text "Get a " (111:6-111:12, 2397-2403)
@@ -531,7 +514,6 @@ root[14]
531514
│ ├─0 typeExpression "Point" (137:14-137:21, 3429-3436)
532515
│ └─1 text "Point in document" (137:22-137:39, 3437-3454)
533516
├─10 comment[2] (140:5-144:8, 3518-3608)
534-
│ │ code: null
535517
│ ├─0 description[1] (141:8-141:45, 3529-3566)
536518
│ │ └─0 paragraph[3] (141:8-141:45, 3529-3566)
537519
│ │ ├─0 text "Current offset (" (141:8-141:24, 3529-3545)
@@ -541,7 +523,6 @@ root[14]
541523
│ ├─0 typeExpression "number" (143:13-143:21, 3586-3594)
542524
│ └─1 text "index" (143:22-143:27, 3595-3600)
543525
├─11 comment[2] (147:5-151:8, 3640-3727)
544-
│ │ code: null
545526
│ ├─0 description[1] (148:8-148:43, 3651-3686)
546527
│ │ └─0 paragraph[3] (148:8-148:43, 3651-3686)
547528
│ │ ├─0 text "Current line (" (148:8-148:22, 3651-3665)
@@ -551,7 +532,6 @@ root[14]
551532
│ ├─0 typeExpression "number" (150:13-150:21, 3706-3714)
552533
│ └─1 text "line" (150:22-150:26, 3715-3719)
553534
├─12 comment[2] (154:5-158:8, 3759-3858)
554-
│ │ code: null
555535
│ ├─0 description[1] (155:8-155:53, 3770-3815)
556536
│ │ └─0 paragraph[3] (155:8-155:53, 3770-3815)
557537
│ │ ├─0 text "Current " (155:8-155:16, 3770-3778)
@@ -561,7 +541,6 @@ root[14]
561541
│ ├─0 typeExpression "Point" (157:15-157:22, 3837-3844)
562542
│ └─1 text "point" (157:23-157:28, 3845-3850)
563543
└─13 comment[6] (177:3-191:6, 4310-4756)
564-
code: null
565544
├─0 description[4] (178:6-181:78, 4319-4506)
566545
│ ├─0 paragraph[5] (178:6-179:30, 4319-4423)
567546
│ │ ├─0 text "Get the next " (178:6-178:19, 4319-4332)
@@ -596,7 +575,6 @@ root[14]
596575
exports[`integration:fromDocs > non-empty snippet > snippet sample 0 1`] = `
597576
root[1]
598577
└─0 comment[7] (110:3-138:6, 2388-3460)
599-
code: null
600578
├─0 description[12] (111:6-128:42, 2397-3216)
601579
│ ├─0 paragraph[5] (111:6-111:53, 2397-2444)
602580
│ │ ├─0 text "Get a " (111:6-111:12, 2397-2403)

src/__snapshots__/util.markdown.snap

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`unit:parseMarkdown > should return mdast child node array 1`] = `
3+
exports[`unit:parseMarkdown > sample 0 1`] = `
4+
root[1] (63:8-63:55, 1564-1611)
5+
└─0 paragraph[1] (63:8-63:55, 1564-1611)
6+
└─0 text "increase of index of x used to calculate z by 1" (63:8-63:55, 1564-1611)
7+
`;
8+
9+
exports[`unit:parseMarkdown > sample 1 1`] = `
410
root[12] (111:6-128:42, 2397-3216)
511
├─0 paragraph[5] (111:6-111:53, 2397-2444)
612
│ ├─0 text "Get a " (111:6-111:12, 2397-2403)

src/__tests__/util.integration.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ describe('integration:fromDocs', () => {
3636
mdastExtensions: [directiveFromMarkdown()],
3737
micromarkExtensions: [directive()]
3838
}],
39-
[await read('__fixtures__/dbl-linear.ts'), { codeblocks: [/@example/] }],
39+
[await read('__fixtures__/dbl-linear.ts'), {
40+
codeblocks: [/@example/],
41+
multiline: true
42+
}],
4043
[await read('__fixtures__/reader.ts')]
4144
])('document sample %#', (file, options) => {
4245
expect(testSubject(file, options)).toMatchSnapshot()

src/__tests__/util.markdown.spec.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @module docast-util-from-docs/tests/util/markdown/unit
44
*/
55

6-
import type { Point } from '@flex-development/docast'
6+
import type { ParseMarkdownOptions } from '#src/interfaces'
77
import { constant } from '@flex-development/tutils'
88
import type { RootContent } from 'mdast'
99
import { read } from 'to-vfile'
@@ -12,18 +12,7 @@ import type { VFile } from 'vfile'
1212
import type { TestContext } from 'vitest'
1313
import testSubject from '../util.markdown'
1414

15-
describe('unit:parseMarkdown', () => {
16-
let end: Point
17-
let file: VFile
18-
let start: Point
19-
20-
beforeAll(async () => {
21-
file = await read('__fixtures__/reader.ts')
22-
23-
end = { column: 42, line: 128, offset: 3216 }
24-
start = { column: 6, line: 111, offset: 2397 }
25-
})
26-
15+
describe('unit:parseMarkdown', async () => {
2716
beforeEach((ctx: TestContext): void => {
2817
ctx.expect.addSnapshotSerializer({
2918
print: (val: unknown): string => {
@@ -51,12 +40,28 @@ describe('unit:parseMarkdown', () => {
5140
})
5241
})
5342

54-
it('should return mdast child node array', () => {
43+
it.each<[VFile, ParseMarkdownOptions]>([
44+
[await read('__fixtures__/dbl-linear.ts'), {
45+
position: {
46+
end: { column: 55, line: 63, offset: 1611 },
47+
start: { column: 8, line: 63, offset: 1564 }
48+
}
49+
}],
50+
[await read('__fixtures__/reader.ts'), {
51+
position: {
52+
end: { column: 42, line: 128, offset: 3216 },
53+
start: { column: 6, line: 111, offset: 2397 }
54+
}
55+
}]
56+
])('sample %#', (file, options) => {
5557
// Arrange
56-
const value: string = String(file).slice(start.offset, end.offset)
58+
const value: string = String(file).slice(
59+
options.position.start.offset,
60+
options.position.end.offset
61+
)
5762

5863
// Act
59-
const result = testSubject(value, { position: { end, start } })
64+
const result = testSubject(value, options)
6065

6166
// Expect
6267
expect(result).to.be.an('array').that.is.not.empty
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @file Type Tests - LexerOptions
3+
* @module docast-util-from-docs/interfaces/tests/unit-d/LexerOptions
4+
*/
5+
6+
import type { Point } from '@flex-development/docast'
7+
import type { Nilable } from '@flex-development/tutils'
8+
import type TestSubject from '../options-lexer'
9+
10+
describe('unit-d:interfaces/LexerOptions', () => {
11+
it('should match [from?: Nilable<Point>]', () => {
12+
expectTypeOf<TestSubject>()
13+
.toHaveProperty('from')
14+
.toEqualTypeOf<Nilable<Point>>()
15+
})
16+
17+
it('should match [multiline?: Nilable<boolean>]', () => {
18+
expectTypeOf<TestSubject>()
19+
.toHaveProperty('multiline')
20+
.toEqualTypeOf<Nilable<boolean>>()
21+
})
22+
})

src/interfaces/__tests__/options-markdown-parse.spec-d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ describe('unit-d:interfaces/ParseMarkdownOptions', () => {
1919
.toEqualTypeOf<Nilable<boolean>>()
2020
})
2121

22+
it('should match [multiline?: Nilable<boolean>]', () => {
23+
expectTypeOf<TestSubject>()
24+
.toHaveProperty('multiline')
25+
.toEqualTypeOf<Nilable<boolean>>()
26+
})
27+
2228
it('should match [position: Position]', () => {
2329
expectTypeOf<TestSubject>()
2430
.toHaveProperty('position')

0 commit comments

Comments
 (0)