File tree Expand file tree Collapse file tree 3 files changed +82
-0
lines changed
test/fixtures/start-with-single-newline Expand file tree Collapse file tree 3 files changed +82
-0
lines changed Original file line number Diff line number Diff line change @@ -371,6 +371,20 @@ export const convertRawTypstAstObjectToTextlintAstObject = (
371
371
return endOffset ;
372
372
} ;
373
373
374
+ // If the source code starts with a single newline, add a Break node before the first node.
375
+ if ( textlintAstObject . c ) {
376
+ const rootChildrenStartLocation = extractLocation (
377
+ textlintAstObject . c [ 0 ] . s ,
378
+ textlintAstObject . c [ 0 ] . c ,
379
+ ) ;
380
+ if ( rootChildrenStartLocation . start . line === 2 ) {
381
+ // @ts -expect-error
382
+ textlintAstObject . c . unshift ( {
383
+ s : "<span style='color:#7dcfff'>Marked::Parbreak</span> <1:0~2:0>" ,
384
+ } ) ;
385
+ }
386
+ }
387
+
374
388
calculateOffsets ( textlintAstObject ) ;
375
389
376
390
// Root node is always `Document` node
Original file line number Diff line number Diff line change
1
+
2
+ This is test that starts with a single newline.
Original file line number Diff line number Diff line change
1
+ {
2
+ "children" : [
3
+ {
4
+ "value" : " \n " ,
5
+ "raw" : " \n " ,
6
+ "range" : [0 , 1 ],
7
+ "loc" : {
8
+ "start" : {
9
+ "line" : 1 ,
10
+ "column" : 0
11
+ },
12
+ "end" : {
13
+ "line" : 2 ,
14
+ "column" : 0
15
+ }
16
+ },
17
+ "type" : " Break"
18
+ },
19
+ {
20
+ "loc" : {
21
+ "start" : {
22
+ "line" : 2 ,
23
+ "column" : 0
24
+ },
25
+ "end" : {
26
+ "line" : 2 ,
27
+ "column" : 47
28
+ }
29
+ },
30
+ "range" : [1 , 48 ],
31
+ "raw" : " This is test that starts with a single newline." ,
32
+ "type" : " Paragraph" ,
33
+ "children" : [
34
+ {
35
+ "value" : " This is test that starts with a single newline." ,
36
+ "raw" : " This is test that starts with a single newline." ,
37
+ "range" : [1 , 48 ],
38
+ "loc" : {
39
+ "start" : {
40
+ "line" : 2 ,
41
+ "column" : 0
42
+ },
43
+ "end" : {
44
+ "line" : 2 ,
45
+ "column" : 47
46
+ }
47
+ },
48
+ "type" : " Str"
49
+ }
50
+ ]
51
+ }
52
+ ],
53
+ "raw" : " \n This is test that starts with a single newline." ,
54
+ "range" : [0 , 48 ],
55
+ "loc" : {
56
+ "start" : {
57
+ "line" : 1 ,
58
+ "column" : 0
59
+ },
60
+ "end" : {
61
+ "line" : 2 ,
62
+ "column" : 47
63
+ }
64
+ },
65
+ "type" : " Document"
66
+ }
You can’t perform that action at this time.
0 commit comments