Skip to content

Optional level summary #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
truncate missing level description
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed May 30, 2020
commit 49d117ebbb0329266e48d8fbec411bbab741a39c
18 changes: 13 additions & 5 deletions src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@ export function parseMdContent(md: string): TutorialFrame | never {
const stepMatch = section.match(stepRegex);

if (levelMatch) {
const {
levelId,
levelTitle,
levelSummary,
levelContent,
} = levelMatch.groups;
const level = {
[levelMatch.groups.levelId]: {
id: levelMatch.groups.levelId,
title: levelMatch.groups.levelTitle,
summary: levelMatch.groups.levelSummary.trim(),
content: levelMatch.groups.levelContent.trim(),
[levelId]: {
id: levelId,
title: levelTitle,
summary: levelSummary
? levelSummary.trim()
: _.truncate(levelContent, { length: 80, omission: "..." }),
content: levelContent.trim(),
},
};

Expand Down
56 changes: 56 additions & 0 deletions tests/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,60 @@ levels:
};
expect(result.levels).toEqual(expected.levels);
});

it("should parse a level with no level description", () => {
const md = `# Title

Description.

## L1 Put Level's title here

Some text that becomes the summary
`;

const yaml = `version: "0.1.0"
levels:
- id: L1
`;
const result = parse(md, yaml);
const expected = {
levels: [
{
id: "L1",
title: "Put Level's title here",
summary: "Some text that becomes the summary",
content: "Some text that becomes the summary",
},
],
};
expect(result.levels).toEqual(expected.levels);
});

it("should truncate a level description", () => {
const md = `# Title

Description.

## L1 Put Level's title here

Some text that becomes the summary and goes beyond the maximum length of 80 so that it gets truncated at the end
`;

const yaml = `version: "0.1.0"
levels:
- id: L1
`;
const result = parse(md, yaml);
const expected = {
levels: [
{
id: "L1",
title: "Put Level's title here",
summary: "Some text that becomes the summary",
content: "Some text that becomes the summary",
},
],
};
expect(result.levels[0].summary).toMatch(/\.\.\.$/);
});
});