@@ -45,15 +45,15 @@ export function parseMdContent(md: string): TutorialFrame | never {
4545 mdContent . summary . description = summaryMatch . groups . tutorialDescription . trim ( ) ;
4646 }
4747
48- let current = { level : - 1 , step : 0 } ;
48+ let current = { level : - 1 , step : - 1 } ;
4949 // Identify each part of the content
5050 parts . forEach ( ( section : string ) => {
5151 // match level
5252 const levelRegex = / ^ ( # { 2 } \s (?< levelId > L ? \d + \. ? ) \s (?< levelTitle > .* ) [ \n \r ] * ( > \s (?< levelSummary > .* ) ) ? [ \n \r ] + (?< levelContent > [ ^ ] * ) ) / ;
5353 const levelMatch : RegExpMatchArray | null = section . match ( levelRegex ) ;
5454
5555 if ( levelMatch && levelMatch . groups ) {
56- current = { level : current . level + 1 , step : 0 } ;
56+ current = { level : current . level + 1 , step : - 1 } ;
5757 const { levelTitle, levelSummary, levelContent } = levelMatch . groups ;
5858
5959 // @ts -ignore
@@ -75,15 +75,15 @@ export function parseMdContent(md: string): TutorialFrame | never {
7575 const stepRegex = / ^ ( # { 3 } \s (?< stepTitle > .* ) [ \n \r ] + (?< stepContent > [ ^ ] * ) ) / ;
7676 const stepMatch : RegExpMatchArray | null = section . match ( stepRegex ) ;
7777 if ( stepMatch && stepMatch . groups ) {
78+ current = { level : current . level , step : current . step + 1 } ;
7879 const { stepId, stepContent } = stepMatch . groups ;
7980 mdContent . levels [ current . level ] . steps [ current . step ] = {
8081 id : `${ current . level + 1 } .${ current . step + 1 } ` ,
8182 content : stepContent . trim ( ) ,
8283 } ;
83- current = { ...current , step : current . step + 1 } ;
8484 } else {
8585 // 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 ] + ) + / ;
8787 const hintMatch = section . match ( hintDetectRegex ) ;
8888 if ( ! ! hintMatch ) {
8989 const hintItemRegex = / [ \n \r ] + \* \s / ;
@@ -142,84 +142,44 @@ export function parse(params: ParseParams): any {
142142 level = { ...configLevelProps , ...level } ;
143143 if ( steps ) {
144144 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 ] ;
161161 }
162- step . setup . commits = params . commits [ stepSetupKey ] ;
163- }
164162
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 ] ;
171171 }
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 ) ;
173176 }
174177 // update level step
175178 level . steps [ index ] = step ;
176179 } ) ;
177180 }
178181 }
179182
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-
223183 if ( params . commits [ level . id ] ) {
224184 if ( ! level . setup ) {
225185 level . setup = { } ;
0 commit comments