Skip to content

level summary truncate use only first line #32

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 1 commit into from
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export function parseMdContent(md: string): TutorialFrame | never {
title: levelTitle.trim(),
summary: levelSummary
? levelSummary.trim()
: truncate(levelContent.trim(), { length: 80, omission: "..." }),
: truncate(levelContent.split(/[\n\r]+/)[0].trim(), {
length: 80,
omission: "...",
}),
content: levelContent.trim(),
};
current = { level: levelId, step: "0" };
Expand Down
31 changes: 31 additions & 0 deletions tests/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,37 @@ Some text that becomes the summary and goes beyond the maximum length of 80 so t
expect(result.levels[0].summary).toMatch(/\.\.\.$/);
});

it("should only truncate the first line of a level description", () => {
const md = `# Title

Description.

## L1 Put Level's title here

Some text.

But not including this line.
`;

const skeleton = { levels: [{ id: "L1" }] };
const result = parse({
text: md,
skeleton,
commits: {},
});
const expected = {
levels: [
{
id: "L1",
title: "Put Level's title here",
summary: "Some text.",
content: "Some text.\n\nBut not including this line.",
},
],
};
expect(result.levels[0].summary).toEqual("Some text.");
});

it("should match line breaks with double line breaks for proper spacing", () => {
const md = `# Title

Expand Down