File tree Expand file tree Collapse file tree 2 files changed +44
-8
lines changed Expand file tree Collapse file tree 2 files changed +44
-8
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ export function parseMdContent(md: string): TutorialFrame | never {
53
53
// Identify each part of the content
54
54
parts . forEach ( ( section : string ) => {
55
55
// match level
56
- const levelRegex = / ^ ( # { 2 } \s (?< levelId > L \d + ) \s (?< levelTitle > .* ) [ \n \r ] * ( > \s * (?< levelSummary > .* ) ) ? [ \n \r ] + (?< levelContent > [ ^ ] * ) ) / ;
56
+ const levelRegex = / ^ ( # { 2 } \s (?< levelId > L \d + ) \s (?< levelTitle > .* ) [ \n \r ] * ( > \s (?< levelSummary > .* ) ) ? [ \n \r ] + (?< levelContent > [ ^ ] * ) ) / ;
57
57
const levelMatch : RegExpMatchArray | null = section . match ( levelRegex ) ;
58
58
if ( levelMatch && levelMatch . groups ) {
59
59
const {
@@ -67,12 +67,13 @@ export function parseMdContent(md: string): TutorialFrame | never {
67
67
mdContent . levels [ levelId ] = {
68
68
id : levelId ,
69
69
title : levelTitle . trim ( ) ,
70
- summary : levelSummary
71
- ? levelSummary . trim ( )
72
- : truncate ( levelContent . split ( / [ \n \r ] + / ) [ 0 ] . trim ( ) , {
73
- length : 80 ,
74
- omission : "..." ,
75
- } ) ,
70
+ summary :
71
+ levelSummary && levelSummary . trim ( ) . length
72
+ ? levelSummary . trim ( )
73
+ : truncate ( levelContent . split ( / [ \n \r ] + / ) [ 0 ] . trim ( ) , {
74
+ length : 80 ,
75
+ omission : "..." ,
76
+ } ) ,
76
77
content : levelContent . trim ( ) ,
77
78
} ;
78
79
current = { level : levelId , step : "0" } ;
Original file line number Diff line number Diff line change @@ -191,10 +191,45 @@ But not including this line.
191
191
title : "Put Level's title here" ,
192
192
summary : "Some text." ,
193
193
content : "Some text.\n\nBut not including this line." ,
194
+ steps : [ ] ,
195
+ } ,
196
+ ] ,
197
+ } ;
198
+ expect ( result . levels [ 0 ] ) . toEqual ( expected . levels [ 0 ] ) ;
199
+ } ) ;
200
+
201
+ it ( "should truncate a level with an empty summary" , ( ) => {
202
+ const md = `# Title
203
+
204
+ Description.
205
+
206
+ ## L1 Put Level's title here
207
+
208
+ >
209
+
210
+ Some text.
211
+
212
+ But not including this line.
213
+ ` ;
214
+
215
+ const skeleton = { levels : [ { id : "L1" } ] } ;
216
+ const result = parse ( {
217
+ text : md ,
218
+ skeleton,
219
+ commits : { } ,
220
+ } ) ;
221
+ const expected = {
222
+ levels : [
223
+ {
224
+ id : "L1" ,
225
+ title : "Put Level's title here" ,
226
+ summary : "Some text." ,
227
+ content : "Some text.\n\nBut not including this line." ,
228
+ steps : [ ] ,
194
229
} ,
195
230
] ,
196
231
} ;
197
- expect ( result . levels [ 0 ] . summary ) . toEqual ( "Some text." ) ;
232
+ expect ( result . levels [ 0 ] ) . toEqual ( expected . levels [ 0 ] ) ;
198
233
} ) ;
199
234
200
235
it ( "should match line breaks with double line breaks for proper spacing" , ( ) => {
You can’t perform that action at this time.
0 commit comments