Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8af3bf6

Browse files
committed
update parser progress
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent67bdfd7 commit8af3bf6

File tree

3 files changed

+97
-97
lines changed

3 files changed

+97
-97
lines changed

‎src/utils/parse.ts

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import * as T from "../../typings/tutorial";
44

55
typeTutorialFrame={
66
summary:T.TutorialSummary;
7-
levels:{
8-
[levelKey:string]:T.Level;
9-
};
10-
steps:{[stepKey:string]:Partial<T.Step>};
7+
levels:T.Level[];
118
};
129

1310
exportfunctionparseMdContent(md:string):TutorialFrame|never{
@@ -33,8 +30,7 @@ export function parseMdContent(md: string): TutorialFrame | never {
3330
title:"",
3431
description:"",
3532
},
36-
levels:{},
37-
steps:{},
33+
levels:[],
3834
};
3935

4036
// Capture summary
@@ -49,23 +45,20 @@ export function parseMdContent(md: string): TutorialFrame | never {
4945
mdContent.summary.description=summaryMatch.groups.tutorialDescription.trim();
5046
}
5147

52-
letcurrent={level:"0",step:"0"};
48+
letcurrent={level:-1,step:0};
5349
// Identify each part of the content
5450
parts.forEach((section:string)=>{
5551
// match level
56-
constlevelRegex=/^(#{2}\s(?<levelId>L\d+)\s(?<levelTitle>.*)[\n\r]*(>\s(?<levelSummary>.*))?[\n\r]+(?<levelContent>[^]*))/;
52+
constlevelRegex=/^(#{2}\s(?<levelId>L?\d+\.?)\s(?<levelTitle>.*)[\n\r]*(>\s(?<levelSummary>.*))?[\n\r]+(?<levelContent>[^]*))/;
5753
constlevelMatch:RegExpMatchArray|null=section.match(levelRegex);
54+
5855
if(levelMatch&&levelMatch.groups){
59-
const{
60-
levelId,
61-
levelTitle,
62-
levelSummary,
63-
levelContent,
64-
}=levelMatch.groups;
56+
current={level:current.level+1,step:0};
57+
const{ levelTitle, levelSummary, levelContent}=levelMatch.groups;
6558

6659
//@ts-ignore
67-
mdContent.levels[levelId]={
68-
id:levelId,
60+
mdContent.levels[current.level]={
61+
id:(current.level+1).toString(),
6962
title:levelTitle.trim(),
7063
summary:
7164
levelSummary&&levelSummary.trim().length
@@ -75,20 +68,21 @@ export function parseMdContent(md: string): TutorialFrame | never {
7568
omission:"...",
7669
}),
7770
content:levelContent.trim(),
71+
steps:[],
7872
};
79-
current={level:levelId,step:"0"};
8073
}else{
8174
// match step
82-
conststepRegex=/^(#{3}\s(?<stepId>(?<levelId>L\d+)S\d+)\s(?<stepTitle>.*)[\n\r]+(?<stepContent>[^]*))/;
75+
conststepRegex=/^(#{3}\s\(?<stepTitle>.*)[\n\r]+(?<stepContent>[^]*)/;
8376
conststepMatch:RegExpMatchArray|null=section.match(stepRegex);
8477
if(stepMatch&&stepMatch.groups){
8578
const{ stepId, stepContent}=stepMatch.groups;
86-
87-
mdContent.steps[stepId]={
79+
mdContent.levels[current.level].steps[current.step]={
8880
id:stepId,
8981
content:stepContent.trim(),
82+
setup:{},
83+
solution:{},
9084
};
91-
current={ ...current,step:stepId};
85+
current={ ...current,step:current.step+1};
9286
}else{
9387
// parse hints from stepContent
9488
consthintDetectRegex=/^(#{4}\sHINTS[\n\r]+(\*\s(?<hintContent>[^]*))[\n\r]+)+/;
@@ -100,7 +94,7 @@ export function parseMdContent(md: string): TutorialFrame | never {
10094
.slice(1)// remove #### HINTS
10195
.map((h)=>h.trim());
10296
if(hints.length){
103-
mdContent.steps[current.step].hints=hints;
97+
mdContent.levels[current.level].steps[current.step].hints=hints;
10498
}
10599
}
106100
}
@@ -135,72 +129,78 @@ export function parse(params: ParseParams): any {
135129
};
136130
}
137131

138-
// merge content and tutorial
139-
if(params.skeleton.levels&&params.skeleton.levels.length){
140-
parsed.levels=params.skeleton.levels
141-
.map((level:T.Level,levelIndex:number)=>{
142-
constlevelContent=mdContent.levels[level.id];
132+
// merge content levels and tutorial
143133

144-
if(!levelContent){
145-
returnnull;
146-
}
147-
148-
level={ ...level, ...levelContent};
149-
150-
// add level setup commits
151-
constlevelSetupKey=level.id;
152-
if(params.commits[levelSetupKey]){
153-
level.setup={
154-
...(level.setup||{}),
155-
commits:params.commits[levelSetupKey],
156-
};
157-
}
134+
parsed.levels=mdContent.levels.map((level:T.Level,levelIndex:number)=>{
135+
// add level setup commits
136+
constlevelId=level.id;
137+
if(params.commits[levelId]){
138+
if(!level.setup){
139+
level.setup={};
140+
}
141+
level.setup.commits=params.commits[levelId];
142+
}
158143

159-
// add level step commits
160-
try{
161-
level.steps=(level.steps||[]).map(
162-
(step:T.Step,stepIndex:number)=>{
163-
conststepKey=`${levelSetupKey}S${stepIndex+1}`;
164-
conststepSetupKey=`${stepKey}Q`;
165-
if(params.commits[stepSetupKey]){
166-
if(!step.setup){
167-
step.setup={
168-
commits:[],
169-
};
170-
}
171-
step.setup.commits=params.commits[stepSetupKey];
172-
}
173-
174-
conststepSolutionKey=`${stepKey}A`;
175-
if(params.commits[stepSolutionKey]){
176-
if(!step.solution){
177-
step.solution={
178-
commits:[],
179-
};
180-
}
181-
step.solution.commits=params.commits[stepSolutionKey];
182-
}
183-
184-
// add markdown
185-
conststepMarkdown:Partial<T.Step>=mdContent.steps[step.id];
186-
if(stepMarkdown){
187-
step={ ...step, ...stepMarkdown};
188-
}
189-
190-
step.id=`${stepKey}`;
191-
returnstep;
192-
}
193-
);
194-
}catch(error){
195-
console.log(JSON.stringify(level.steps));
196-
console.error("Error parsing level steps");
197-
console.error(error.message);
198-
}
144+
// get yaml for level
145+
constconfigLevel=params.skeleton.levels.find(
146+
(l:Partial<T.Level>)=>l.id===levelId
147+
);
148+
149+
letconfigSteps={};
150+
if(configLevel){
151+
const{ steps, ...configLevelProps}=configLevel;
152+
level={ ...configLevelProps, ...level};
153+
if(steps){
154+
steps.forEach((s:T.Step)=>{
155+
configSteps[s.id]=s;
156+
});
157+
}
158+
}
199159

200-
returnlevel;
201-
})
202-
.filter((l:T.Level|null)=>!!l);
203-
}
160+
// add level step commits
161+
// try {
162+
// level.steps = (level.steps || []).map(
163+
// (step: T.Step, stepIndex: number) => {
164+
// const stepKey = `${levelId}S${stepIndex + 1}`;
165+
// const stepSetupKey = `${stepKey}Q`;
166+
// if (params.commits[stepSetupKey]) {
167+
// if (!step.setup) {
168+
// step.setup = {
169+
// commits: [],
170+
// };
171+
// }
172+
// step.setup.commits = params.commits[stepSetupKey];
173+
// }
174+
175+
// const stepSolutionKey = `${stepKey}A`;
176+
// if (params.commits[stepSolutionKey]) {
177+
// if (!step.solution) {
178+
// step.solution = {
179+
// commits: [],
180+
// };
181+
// }
182+
// step.solution.commits = params.commits[stepSolutionKey];
183+
// }
184+
185+
// // add markdown
186+
// const stepMarkdown: Partial<T.Step> =
187+
// mdContent.levels[level.id].steps[step.id];
188+
// if (stepMarkdown) {
189+
// step = { ...step, ...stepMarkdown };
190+
// }
191+
192+
// step.id = `${stepKey}`;
193+
// return step;
194+
// }
195+
// );
196+
// } catch (error) {
197+
// console.log(JSON.stringify(level.steps));
198+
// console.error("Error parsing level steps");
199+
// console.error(error.message);
200+
// }
201+
202+
returnlevel;
203+
});
204204

205205
returnparsed;
206206
}

‎tests/parse.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Short description to be shown as a tutorial's subtitle.
3232
3333
Description.
3434
35-
## Put Level's title here
35+
##1.Put Level's title here
3636
3737
> Level's summary: a short description of the level's content in one line.
3838
@@ -68,7 +68,7 @@ Some text
6868
6969
Description.
7070
71-
## Put Level's title here
71+
##1.Put Level's title here
7272
7373
> Level's summary: a short description of the level's content in one line.
7474
@@ -112,7 +112,7 @@ Some text
112112
113113
Description.
114114
115-
## Put Level's title here
115+
##1.Put Level's title here
116116
117117
Some text that becomes the summary
118118
`;
@@ -142,7 +142,7 @@ Some text that becomes the summary
142142
143143
Description.
144144
145-
## Put Level's title here
145+
##1.Put Level's title here
146146
147147
Some text that becomes the summary and goes beyond the maximum length of 80 so that it gets truncated at the end
148148
`;
@@ -171,7 +171,7 @@ Some text that becomes the summary and goes beyond the maximum length of 80 so t
171171
172172
Description.
173173
174-
## 1 Put Level's title here
174+
## 1. Put Level's title here
175175
176176
Some text.
177177
@@ -203,7 +203,7 @@ But not including this line.
203203
204204
Description.
205205
206-
## Put Level's title here
206+
##1.Put Level's title here
207207
208208
>
209209
@@ -239,7 +239,7 @@ Description.
239239
240240
Second description line
241241
242-
## Titles
242+
##1.Titles
243243
244244
First line
245245
@@ -275,7 +275,7 @@ Third line
275275
276276
Description.
277277
278-
## Title
278+
##1.Title
279279
280280
First line
281281
@@ -331,7 +331,7 @@ The first step
331331
332332
Description.
333333
334-
## Title
334+
##1.Title
335335
336336
First line
337337
@@ -387,7 +387,7 @@ The first step
387387
388388
Description.
389389
390-
## Title
390+
##1.Title
391391
392392
First line
393393
@@ -935,7 +935,7 @@ Description.
935935
});
936936
});
937937

938-
describe("hints",()=>{
938+
xdescribe("hints",()=>{
939939
it("should parse hints for a step",()=>{
940940
constmd=`# Title
941941

‎typings/tutorial.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export type TutorialSummary = {
4848

4949
exporttypeStepActions={
5050
commands?:string[];
51-
commits:string[];
51+
commits?:string[];
5252
files?:string[];
5353
watchers?:string[];
5454
filter?:string;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp