@@ -45,20 +45,25 @@ 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 : - 1 } ;
48
+ let current = { levelId : "" , levelIndex : - 1 , stepIndex : - 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 : - 1 } ;
56
+ const levelId = levelMatch . groups . levelId . replace ( "." , "" ) ;
57
+ current = {
58
+ levelId : levelId ,
59
+ levelIndex : current . levelIndex + 1 ,
60
+ stepIndex : - 1 ,
61
+ } ;
57
62
const { levelTitle, levelSummary, levelContent } = levelMatch . groups ;
58
63
59
64
// @ts -ignore
60
- mdContent . levels [ current . level ] = {
61
- id : ( current . level + 1 ) . toString ( ) ,
65
+ mdContent . levels [ current . levelIndex ] = {
66
+ id : levelId ,
62
67
title : levelTitle . trim ( ) ,
63
68
summary :
64
69
levelSummary && levelSummary . trim ( ) . length
@@ -75,10 +80,14 @@ export function parseMdContent(md: string): TutorialFrame | never {
75
80
const stepRegex = / ^ ( # { 3 } \s (?< stepTitle > .* ) [ \n \r ] + (?< stepContent > [ ^ ] * ) ) / ;
76
81
const stepMatch : RegExpMatchArray | null = section . match ( stepRegex ) ;
77
82
if ( stepMatch && stepMatch . groups ) {
78
- current = { level : current . level , step : current . step + 1 } ;
83
+ current = {
84
+ levelId : current . levelId ,
85
+ levelIndex : current . levelIndex ,
86
+ stepIndex : current . stepIndex + 1 ,
87
+ } ;
79
88
const { stepId, stepContent } = stepMatch . groups ;
80
- mdContent . levels [ current . level ] . steps [ current . step ] = {
81
- id : `${ current . level + 1 } .${ current . step + 1 } ` ,
89
+ mdContent . levels [ current . levelIndex ] . steps [ current . stepIndex ] = {
90
+ id : `${ current . levelId } .${ current . stepIndex + 1 } ` ,
82
91
content : stepContent . trim ( ) ,
83
92
} ;
84
93
} else {
@@ -92,7 +101,9 @@ export function parseMdContent(md: string): TutorialFrame | never {
92
101
. slice ( 1 ) // remove #### HINTS
93
102
. map ( ( h ) => h . trim ( ) ) ;
94
103
if ( hints . length ) {
95
- mdContent . levels [ current . level ] . steps [ current . step ] . hints = hints ;
104
+ mdContent . levels [ current . levelIndex ] . steps [
105
+ current . stepIndex
106
+ ] . hints = hints ;
96
107
}
97
108
}
98
109
}
0 commit comments