From 4a21eecee94955a252c7ea014deaa13f5bd98f76 Mon Sep 17 00:00:00 2001 From: shmck Date: Mon, 15 Jun 2020 19:14:27 -0700 Subject: [PATCH 1/2] setup summary parse tests Signed-off-by: shmck --- tests/parse.test.ts | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/parse.test.ts b/tests/parse.test.ts index 57ea528..c4d6ca9 100644 --- a/tests/parse.test.ts +++ b/tests/parse.test.ts @@ -191,10 +191,45 @@ But not including this line. title: "Put Level's title here", summary: "Some text.", content: "Some text.\n\nBut not including this line.", + steps: [], + }, + ], + }; + expect(result.levels[0]).toEqual(expected.levels[0]); + }); + + it("should truncate a level with an empty summary", () => { + 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.", + steps: [], }, ], }; - expect(result.levels[0].summary).toEqual("Some text."); + expect(result.levels[0]).toEqual(expected.levels[0]); }); it("should match line breaks with double line breaks for proper spacing", () => { From 6c5187c1253e04c2f6136577d7066bea71a65f7c Mon Sep 17 00:00:00 2001 From: shmck Date: Mon, 15 Jun 2020 19:24:14 -0700 Subject: [PATCH 2/2] fix empty summary parser issue Signed-off-by: shmck --- src/utils/parse.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/utils/parse.ts b/src/utils/parse.ts index 66732b9..f8bf49d 100644 --- a/src/utils/parse.ts +++ b/src/utils/parse.ts @@ -53,7 +53,7 @@ export function parseMdContent(md: string): TutorialFrame | never { // Identify each part of the content parts.forEach((section: string) => { // match level - const levelRegex = /^(#{2}\s(?L\d+)\s(?.*)[\n\r]*(>\s*(?.*))?[\n\r]+(?[^]*))/; + const levelRegex = /^(#{2}\s(?L\d+)\s(?.*)[\n\r]*(>\s(?.*))?[\n\r]+(?[^]*))/; const levelMatch: RegExpMatchArray | null = section.match(levelRegex); if (levelMatch && levelMatch.groups) { const { @@ -67,12 +67,13 @@ export function parseMdContent(md: string): TutorialFrame | never { mdContent.levels[levelId] = { id: levelId, title: levelTitle.trim(), - summary: levelSummary - ? levelSummary.trim() - : truncate(levelContent.split(/[\n\r]+/)[0].trim(), { - length: 80, - omission: "...", - }), + summary: + levelSummary && levelSummary.trim().length + ? levelSummary.trim() + : truncate(levelContent.split(/[\n\r]+/)[0].trim(), { + length: 80, + omission: "...", + }), content: levelContent.trim(), }; current = { level: levelId, step: "0" };