Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit72430c6

Browse files
committed
support parsing subtasks
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent7e86b0c commit72430c6

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

‎src/utils/parse.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,39 @@ export function parseMdContent(md: string): TutorialFrame | never {
9191
content:stepContent.trim(),
9292
};
9393
}else{
94-
// parse hints from stepContent
9594
consthintDetectRegex=/^(#{4}\sHINTS[\n\r]+([\*|\-]\s(?<hintContent>[^]*))[\n\r]+)+/;
9695
consthintMatch=section.match(hintDetectRegex);
97-
if(!!hintMatch){
98-
consthintItemRegex=/[\n\r]+[\*|\-]\s/;
99-
consthints=section
100-
.split(hintItemRegex)
101-
.slice(1)// remove #### HINTS
102-
.map((h)=>h.trim());
103-
if(hints.length){
104-
mdContent.levels[current.levelIndex].steps[
105-
current.stepIndex
106-
].hints=hints;
107-
}
96+
constsubtaskDetectRegex=/^(#{4}\sSUBTASKS[\n\r]+([\*|\-]\s(?<subtaskContent>[^]*))[\n\r]+)+/;
97+
constsubtaskMatch=section.match(subtaskDetectRegex);
98+
constlistItemregex=/[\n\r]+[\*|\-]\s/;
99+
100+
switch(true){
101+
// parse hints from stepContent
102+
case!!hintMatch:
103+
consthints=section
104+
.split(listItemregex)
105+
.slice(1)// remove #### HINTS
106+
.map((h)=>h.trim());
107+
if(hints.length){
108+
mdContent.levels[current.levelIndex].steps[
109+
current.stepIndex
110+
].hints=hints;
111+
}
112+
return;
113+
// parse subtasks from stepContent
114+
case!!subtaskMatch:
115+
constsubtasks=section
116+
.split(listItemregex)
117+
.slice(1)// remove #### SUBTASKS
118+
.map((h)=>h.trim());
119+
if(subtasks.length){
120+
mdContent.levels[current.levelIndex].steps[
121+
current.stepIndex
122+
].subtasks=subtasks;
123+
}
124+
return;
125+
default:
126+
console.warn(`No build parser match found for:\n${section}\n`);
108127
}
109128
}
110129
}

‎tests/parse.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,8 @@ Create a function \`add\` that can take a variety of params.
14291429
14301430
- Add one number
14311431
- Add two numbers
1432-
- Add three numbers`;
1432+
- Add three numbers
1433+
`;
14331434
constskeleton={
14341435
levels:[
14351436
{
@@ -1453,18 +1454,18 @@ Create a function \`add\` that can take a variety of params.
14531454
{
14541455
id:"1.1",
14551456
setup:{
1456-
subtasks:[
1457-
"Add one number",
1458-
"Add two numbers",
1459-
"Add three numbers",
1460-
],
14611457
commits:["abcdef1"],
14621458
},
14631459
content:
14641460
"Create a function `add` that can take a variety of params.",
14651461
solution:{
14661462
commits:["abcdef2"],
14671463
},
1464+
subtasks:[
1465+
"Add one number",
1466+
"Add two numbers",
1467+
"Add three numbers",
1468+
],
14681469
},
14691470
],
14701471
},
@@ -1478,7 +1479,7 @@ Create a function \`add\` that can take a variety of params.
14781479
"1.1:S":["abcdef2"],
14791480
},
14801481
});
1481-
expect(result.levels).toEqual(expected.levels);
1482+
expect(result.levels[0]).toEqual(expected.levels[0]);
14821483
});
14831484
});
14841485
});

‎typings/tutorial.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type Step = {
2727
content:string;
2828
setup?:StepActions;
2929
solution?:Maybe<StepActions>;
30-
subtasks?:{[testName:string]:boolean};
30+
subtasks?:string[];
3131
hints?:string[];
3232
};
3333

@@ -52,7 +52,7 @@ export type StepActions = {
5252
files?:string[];
5353
watchers?:string[];
5454
filter?:string;
55-
subtasks?:boolean;
55+
subtasks?:string[];
5656
};
5757

5858
exportinterfaceTestRunnerArgs{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp