@@ -49,6 +49,7 @@ export function parseMdContent(md: string): TutorialFrame | never {
4949 mdContent . summary . description = summaryMatch . groups . tutorialDescription . trim ( ) ;
5050 }
5151
52+ let current = { 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 const stepRegex = / ^ ( # { 3 } \s (?< stepId > (?< levelId > L \d + ) S \d + ) \s (?< stepTitle > .* ) [ \n \r ] + (?< stepContent > [ ^ ] * ) ) / ;
7779 const stepMatch : 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+ const hintDetectRegex = / ^ ( # { 4 } \s H I N T S [ \n \r ] + ( \* \s (?< hintContent > [ ^ ] * ) ) [ \n \r ] + ) + / ;
91+ const hintMatch = section . match ( hintDetectRegex ) ;
92+ if ( ! ! hintMatch ) {
93+ const hintItemRegex = / [ \n \r ] + \* \s / ;
94+ const hints = 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 } ) ;
0 commit comments