diff --git a/src/utils/parse.ts b/src/utils/parse.ts index a97f467..66732b9 100644 --- a/src/utils/parse.ts +++ b/src/utils/parse.ts @@ -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" }; diff --git a/tests/parse.test.ts b/tests/parse.test.ts index 7aa1722..57ea528 100644 --- a/tests/parse.test.ts +++ b/tests/parse.test.ts @@ -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