@@ -52,7 +52,7 @@ export function parseMdContent(md: string): TutorialFrame | never {
52
52
// Identify each part of the content
53
53
parts . forEach ( ( section : string ) => {
54
54
// match level
55
- const levelRegex = / ^ ( # # \s (?< levelId > L \d + ) \s (?< levelTitle > .* ) [ \n \r ] * ( > \s * (?< levelSummary > .* ) ) ? [ \n \r ] + (?< levelContent > [ ^ ] * ) ) / ;
55
+ const levelRegex = / ^ ( # { 2 } \s (?< levelId > L \d + ) \s (?< levelTitle > .* ) [ \n \r ] * ( > \s * (?< levelSummary > .* ) ) ? [ \n \r ] + (?< levelContent > [ ^ ] * ) ) / ;
56
56
const levelMatch : RegExpMatchArray | null = section . match ( levelRegex ) ;
57
57
if ( levelMatch && levelMatch . groups ) {
58
58
const {
@@ -73,10 +73,18 @@ export function parseMdContent(md: string): TutorialFrame | never {
73
73
} ;
74
74
} else {
75
75
// match step
76
- const stepRegex = / ^ ( # # # \s (?< stepId > (?< levelId > L \d + ) S \d + ) \s (?< stepTitle > .* ) [ \n \r ] + (?< stepContent > [ ^ ] * ) ) / ;
76
+ const stepRegex = / ^ ( # { 3 } \s (?< stepId > (?< levelId > L \d + ) S \d + ) \s (?< stepTitle > .* ) [ \n \r ] + (?< stepContent > [ ^ ] * ) ) / ;
77
77
const stepMatch : RegExpMatchArray | null = section . match ( stepRegex ) ;
78
78
if ( stepMatch && stepMatch . groups ) {
79
79
const { stepId, stepContent } = stepMatch . groups ;
80
+
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
+
80
88
mdContent . steps [ stepId ] = {
81
89
id : stepId ,
82
90
content : stepContent . trim ( ) ,
@@ -135,39 +143,45 @@ export function parse(params: ParseParams): any {
135
143
}
136
144
137
145
// add level step commits
138
- level . steps = ( level . steps || [ ] ) . map (
139
- ( step : T . Step , stepIndex : number ) => {
140
- const stepKey = `${ levelSetupKey } S${ stepIndex + 1 } ` ;
141
- const stepSetupKey = `${ stepKey } Q` ;
142
- if ( params . commits [ stepSetupKey ] ) {
143
- if ( ! step . setup ) {
144
- step . setup = {
145
- commits : [ ] ,
146
- } ;
146
+ try {
147
+ level . steps = ( level . steps || [ ] ) . map (
148
+ ( step : T . Step , stepIndex : number ) => {
149
+ const stepKey = `${ levelSetupKey } S${ stepIndex + 1 } ` ;
150
+ const stepSetupKey = `${ stepKey } Q` ;
151
+ if ( params . commits [ stepSetupKey ] ) {
152
+ if ( ! step . setup ) {
153
+ step . setup = {
154
+ commits : [ ] ,
155
+ } ;
156
+ }
157
+ step . setup . commits = params . commits [ stepSetupKey ] ;
147
158
}
148
- step . setup . commits = params . commits [ stepSetupKey ] ;
149
- }
150
159
151
- const stepSolutionKey = `${ stepKey } A` ;
152
- if ( params . commits [ stepSolutionKey ] ) {
153
- if ( ! step . solution ) {
154
- step . solution = {
155
- commits : [ ] ,
156
- } ;
160
+ const stepSolutionKey = `${ stepKey } A` ;
161
+ if ( params . commits [ stepSolutionKey ] ) {
162
+ if ( ! step . solution ) {
163
+ step . solution = {
164
+ commits : [ ] ,
165
+ } ;
166
+ }
167
+ step . solution . commits = params . commits [ stepSolutionKey ] ;
157
168
}
158
- step . solution . commits = params . commits [ stepSolutionKey ] ;
159
- }
160
169
161
- // add markdown
162
- const stepMarkdown : Partial < T . Step > = mdContent . steps [ step . id ] ;
163
- if ( stepMarkdown ) {
164
- step = { ...step , ...stepMarkdown } ;
165
- }
170
+ // add markdown
171
+ const stepMarkdown : Partial < T . Step > = mdContent . steps [ step . id ] ;
172
+ if ( stepMarkdown ) {
173
+ step = { ...step , ...stepMarkdown } ;
174
+ }
166
175
167
- step . id = `${ stepKey } ` ;
168
- return step ;
169
- }
170
- ) ;
176
+ step . id = `${ stepKey } ` ;
177
+ return step ;
178
+ }
179
+ ) ;
180
+ } catch ( error ) {
181
+ console . log ( JSON . stringify ( level . steps ) ) ;
182
+ console . error ( "Error parsing level steps" ) ;
183
+ console . error ( error . message ) ;
184
+ }
171
185
172
186
return level ;
173
187
} )
0 commit comments