@@ -45,15 +45,15 @@ export function parseMdContent(md: string): TutorialFrame | never {
45
45
mdContent . summary . description = summaryMatch . groups . tutorialDescription . trim ( ) ;
46
46
}
47
47
48
- let current = { level : - 1 , step : 0 } ;
48
+ let current = { level : - 1 , step : - 1 } ;
49
49
// Identify each part of the content
50
50
parts . forEach ( ( section : string ) => {
51
51
// match level
52
52
const levelRegex = / ^ ( # { 2 } \s (?< levelId > L ? \d + \. ? ) \s (?< levelTitle > .* ) [ \n \r ] * ( > \s (?< levelSummary > .* ) ) ? [ \n \r ] + (?< levelContent > [ ^ ] * ) ) / ;
53
53
const levelMatch : RegExpMatchArray | null = section . match ( levelRegex ) ;
54
54
55
55
if ( levelMatch && levelMatch . groups ) {
56
- current = { level : current . level + 1 , step : 0 } ;
56
+ current = { level : current . level + 1 , step : - 1 } ;
57
57
const { levelTitle, levelSummary, levelContent } = levelMatch . groups ;
58
58
59
59
// @ts -ignore
@@ -75,15 +75,15 @@ export function parseMdContent(md: string): TutorialFrame | never {
75
75
const stepRegex = / ^ ( # { 3 } \s (?< stepTitle > .* ) [ \n \r ] + (?< stepContent > [ ^ ] * ) ) / ;
76
76
const stepMatch : RegExpMatchArray | null = section . match ( stepRegex ) ;
77
77
if ( stepMatch && stepMatch . groups ) {
78
+ current = { level : current . level , step : current . step + 1 } ;
78
79
const { stepId, stepContent } = stepMatch . groups ;
79
80
mdContent . levels [ current . level ] . steps [ current . step ] = {
80
81
id : `${ current . level + 1 } .${ current . step + 1 } ` ,
81
82
content : stepContent . trim ( ) ,
82
83
} ;
83
- current = { ...current , step : current . step + 1 } ;
84
84
} else {
85
85
// parse hints from stepContent
86
- const hintDetectRegex = / ^ ( # { 4 } \s H I N T S [ \n \r ] + ( \* \s (?< hintContent > [ ^ ] * ) ) [ \n \r ] + ) + / ;
86
+ const hintDetectRegex = / ^ ( # { 4 } \s H I N T S [ \n \r ] + ( [ \* | \- ] \s (?< hintContent > [ ^ ] * ) ) [ \n \r ] + ) + / ;
87
87
const hintMatch = section . match ( hintDetectRegex ) ;
88
88
if ( ! ! hintMatch ) {
89
89
const hintItemRegex = / [ \n \r ] + \* \s / ;
@@ -142,84 +142,44 @@ export function parse(params: ParseParams): any {
142
142
level = { ...configLevelProps , ...level } ;
143
143
if ( steps ) {
144
144
steps . forEach ( ( step : T . Step , index : number ) => {
145
- console . log ( "step" , step ) ;
146
- const mdStep = level . steps [ index ] ;
147
- console . log ( "mdStep" , mdStep ) ;
148
- step = {
149
- ...step ,
150
- ...mdStep ,
151
- } ;
152
-
153
- const stepKey = step . id ;
154
- console . log ( "stepKey" , stepKey ) ;
155
- const stepSetupKey = ` ${ stepKey } Q` ;
156
- if ( params . commits [ stepSetupKey ] ) {
157
- if ( ! step . setup ) {
158
- step . setup = {
159
- commits : [ ] ,
160
- } ;
145
+ try {
146
+ const mdStep = level . steps [ index ] ;
147
+
148
+ step = {
149
+ ...step ,
150
+ ...mdStep ,
151
+ } ;
152
+
153
+ const stepSetupKey = ` ${ step . id } Q` ;
154
+ if ( params . commits [ stepSetupKey ] ) {
155
+ if ( ! step . setup ) {
156
+ step . setup = {
157
+ commits : [ ] ,
158
+ } ;
159
+ }
160
+ step . setup . commits = params . commits [ stepSetupKey ] ;
161
161
}
162
- step . setup . commits = params . commits [ stepSetupKey ] ;
163
- }
164
162
165
- const stepSolutionKey = `${ stepKey } A` ;
166
- if ( params . commits [ stepSolutionKey ] ) {
167
- if ( ! step . solution ) {
168
- step . solution = {
169
- commits : [ ] ,
170
- } ;
163
+ const stepSolutionKey = `${ step . id } A` ;
164
+ if ( params . commits [ stepSolutionKey ] ) {
165
+ if ( ! step . solution ) {
166
+ step . solution = {
167
+ commits : [ ] ,
168
+ } ;
169
+ }
170
+ step . solution . commits = params . commits [ stepSolutionKey ] ;
171
171
}
172
- step . solution . commits = params . commits [ stepSolutionKey ] ;
172
+ } catch ( error ) {
173
+ console . error ( "Error parsing level steps" ) ;
174
+ console . warn ( JSON . stringify ( level . steps ) ) ;
175
+ console . error ( error . message ) ;
173
176
}
174
177
// update level step
175
178
level . steps [ index ] = step ;
176
179
} ) ;
177
180
}
178
181
}
179
182
180
- // try {
181
- // level.steps = (level.steps || []).map(
182
- // (step: T.Step, stepIndex: number) => {
183
- // const stepKey = `${levelId}S${stepIndex + 1}`;
184
- // const stepSetupKey = `${stepKey}Q`;
185
- // if (params.commits[stepSetupKey]) {
186
- // if (!step.setup) {
187
- // step.setup = {
188
- // commits: [],
189
- // };
190
- // }
191
- // step.setup.commits = params.commits[stepSetupKey];
192
- // }
193
-
194
- // const stepSolutionKey = `${stepKey}A`;
195
- // if (params.commits[stepSolutionKey]) {
196
- // if (!step.solution) {
197
- // step.solution = {
198
- // commits: [],
199
- // };
200
- // }
201
- // step.solution.commits = params.commits[stepSolutionKey];
202
- // }
203
-
204
- // // add markdown
205
- // const stepMarkdown: Partial<T.Step> =
206
- // mdContent.levels[level.id].steps[step.id];
207
- // if (stepMarkdown) {
208
- // step = { ...step, ...stepMarkdown };
209
- // }
210
-
211
- // step.id = `${stepKey}`;
212
- // return step;
213
- // }
214
- // );
215
- // } catch (error) {
216
- // console.log(JSON.stringify(level.steps));
217
- // console.error("Error parsing level steps");
218
- // console.error(error.message);
219
- // }
220
-
221
- console . log ( params . commits ) ;
222
-
223
183
if ( params . commits [ level . id ] ) {
224
184
if ( ! level . setup ) {
225
185
level . setup = { } ;
0 commit comments