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

Commit52eafaf

Browse files
committed
parse hints
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent142a047 commit52eafaf

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

‎src/utils/parse.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function parseMdContent(md: string): TutorialFrame | never {
4949
mdContent.summary.description=summaryMatch.groups.tutorialDescription.trim();
5050
}
5151

52+
letcurrent={level:"0",step:"0"};
5253
// Identify each part of the content
5354
parts.forEach((section:string)=>{
5455
// match level
@@ -71,24 +72,33 @@ export function parseMdContent(md: string): TutorialFrame | never {
7172
:truncate(levelContent.trim(),{length:80,omission:"..."}),
7273
content:levelContent.trim(),
7374
};
75+
current={level:levelId,step:"0"};
7476
}else{
7577
// match step
7678
conststepRegex=/^(#{3}\s(?<stepId>(?<levelId>L\d+)S\d+)\s(?<stepTitle>.*)[\n\r]+(?<stepContent>[^]*))/;
7779
conststepMatch:RegExpMatchArray|null=section.match(stepRegex);
7880
if(stepMatch&&stepMatch.groups){
7981
const{ stepId, stepContent}=stepMatch.groups;
8082

81-
// parse hints from stepContent
82-
// const hintRegex = /^(#{4}\sHINTS[\n\r]+(?<hintContent>[^]*))/g;
83-
84-
// if (!!stepContent.match(hintRegex)) {
85-
// console.log("HAS HINT");
86-
// }
87-
8883
mdContent.steps[stepId]={
8984
id:stepId,
9085
content:stepContent.trim(),
9186
};
87+
current={ ...current,step:stepId};
88+
}else{
89+
// parse hints from stepContent
90+
consthintDetectRegex=/^(#{4}\sHINTS[\n\r]+(\*\s(?<hintContent>[^]*))[\n\r]+)+/;
91+
consthintMatch=section.match(hintDetectRegex);
92+
if(!!hintMatch){
93+
consthintItemRegex=/[\n\r]+\*\s/;
94+
consthints=section
95+
.split(hintItemRegex)
96+
.slice(1)// remove #### HINTS
97+
.map((h)=>h.trim());
98+
if(hints.length){
99+
mdContent.steps[current.step].hints=hints;
100+
}
101+
}
92102
}
93103
}
94104
});

‎tests/parse.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ Description.
869869
});
870870
});
871871

872-
xdescribe("hints",()=>{
872+
describe("hints",()=>{
873873
it("should parse hints for a step",()=>{
874874
constmd=`# Title
875875
@@ -947,7 +947,7 @@ First level content.
947947
948948
The first step
949949
950-
####Hints
950+
####HINTS
951951
952952
* First Hint with \`markdown\`. See **bold**
953953
* Second Hint has a codeblock
@@ -1019,7 +1019,7 @@ First level content.
10191019
10201020
The first step
10211021
1022-
####Hints
1022+
####HINTS
10231023
10241024
* First Hint with \`markdown\`. See **bold**
10251025
* Second Hint has a codeblock
@@ -1030,7 +1030,7 @@ var a = 1;
10301030
10311031
And spans multiple lines.
10321032
1033-
###L1S2A
1033+
###L1S2
10341034
10351035
The second uninterrupted step
10361036
`;
@@ -1073,7 +1073,7 @@ The second uninterrupted step
10731073
id:"L1S1",
10741074
content:"The first step",
10751075
setup:{
1076-
commits:["abcdef1","123456789"],
1076+
commits:["abcdef1"],
10771077
},
10781078
solution:{
10791079
commits:["123456789"],
@@ -1095,7 +1095,7 @@ The second uninterrupted step
10951095
{},
10961096
],
10971097
};
1098-
expect(result.levels).toEqual(expected.levels);
1098+
expect(result.levels[0]).toEqual(expected.levels[0]);
10991099
});
11001100
});
11011101
});

‎typings/tutorial.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type Step = {
2828
setup:StepActions;
2929
solution:Maybe<StepActions>;
3030
subtasks?:{[testName:string]:boolean};
31+
hints?:string[];
3132
};
3233

3334
/** A tutorial for use in VSCode CodeRoad */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp