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

Commitd03625d

Browse files
authored
Merge pull request#5 from coderoad/feature/tests
Optional level summary
2 parents9c0b8c3 +49d117e commitd03625d

File tree

2 files changed

+109
-6
lines changed

2 files changed

+109
-6
lines changed

‎src/utils/parse.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,20 @@ export function parseMdContent(md: string): TutorialFrame | never {
5353
conststepMatch=section.match(stepRegex);
5454

5555
if(levelMatch){
56+
const{
57+
levelId,
58+
levelTitle,
59+
levelSummary,
60+
levelContent,
61+
}=levelMatch.groups;
5662
constlevel={
57-
[levelMatch.groups.levelId]:{
58-
id:levelMatch.groups.levelId,
59-
title:levelMatch.groups.levelTitle,
60-
summary:levelMatch.groups.levelSummary.trim(),
61-
content:levelMatch.groups.levelContent.trim(),
63+
[levelId]:{
64+
id:levelId,
65+
title:levelTitle,
66+
summary:levelSummary
67+
?levelSummary.trim()
68+
:_.truncate(levelContent,{length:80,omission:"..."}),
69+
content:levelContent.trim(),
6270
},
6371
};
6472

‎tests/parse.test.ts

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe("parse", () => {
1919
expect(result.summary).toEqual(expected.summary);
2020
});
2121

22-
it("should parse a level witha summary",()=>{
22+
it("should parse a level withno steps",()=>{
2323
constmd=`# Title
2424
2525
Description.
@@ -49,4 +49,99 @@ levels:
4949
};
5050
expect(result.levels).toEqual(expected.levels);
5151
});
52+
53+
it("should parse a level with a step",()=>{
54+
constmd=`# Title
55+
56+
Description.
57+
58+
## L1 Put Level's title here
59+
60+
> Level's summary: a short description of the level's content in one line.
61+
62+
Some text
63+
`;
64+
65+
constyaml=`version: "0.1.0"
66+
levels:
67+
- id: L1
68+
setup:
69+
files: []
70+
commits: []
71+
solution:
72+
files: []
73+
commits: []
74+
`;
75+
constresult=parse(md,yaml);
76+
constexpected={
77+
levels:[
78+
{
79+
id:"L1",
80+
title:"Put Level's title here",
81+
summary:
82+
"Level's summary: a short description of the level's content in one line.",
83+
content:"Some text",
84+
setup:{files:[],commits:[]},
85+
solution:{files:[],commits:[]},
86+
},
87+
],
88+
};
89+
expect(result.levels).toEqual(expected.levels);
90+
});
91+
92+
it("should parse a level with no level description",()=>{
93+
constmd=`# Title
94+
95+
Description.
96+
97+
## L1 Put Level's title here
98+
99+
Some text that becomes the summary
100+
`;
101+
102+
constyaml=`version: "0.1.0"
103+
levels:
104+
- id: L1
105+
`;
106+
constresult=parse(md,yaml);
107+
constexpected={
108+
levels:[
109+
{
110+
id:"L1",
111+
title:"Put Level's title here",
112+
summary:"Some text that becomes the summary",
113+
content:"Some text that becomes the summary",
114+
},
115+
],
116+
};
117+
expect(result.levels).toEqual(expected.levels);
118+
});
119+
120+
it("should truncate a level description",()=>{
121+
constmd=`# Title
122+
123+
Description.
124+
125+
## L1 Put Level's title here
126+
127+
Some text that becomes the summary and goes beyond the maximum length of 80 so that it gets truncated at the end
128+
`;
129+
130+
constyaml=`version: "0.1.0"
131+
levels:
132+
- id: L1
133+
`;
134+
constresult=parse(md,yaml);
135+
constexpected={
136+
levels:[
137+
{
138+
id:"L1",
139+
title:"Put Level's title here",
140+
summary:"Some text that becomes the summary",
141+
content:"Some text that becomes the summary",
142+
},
143+
],
144+
};
145+
expect(result.levels[0].summary).toMatch(/\.\.\.$/);
146+
});
52147
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp