Skip to content

Commit 6c5187c

Browse files
committed
fix empty summary parser issue
Signed-off-by: shmck <[email protected]>
1 parent 4a21eec commit 6c5187c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/utils/parse.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function parseMdContent(md: string): TutorialFrame | never {
5353
// Identify each part of the content
5454
parts.forEach((section: string) => {
5555
// match level
56-
const levelRegex = /^(#{2}\s(?<levelId>L\d+)\s(?<levelTitle>.*)[\n\r]*(>\s*(?<levelSummary>.*))?[\n\r]+(?<levelContent>[^]*))/;
56+
const levelRegex = /^(#{2}\s(?<levelId>L\d+)\s(?<levelTitle>.*)[\n\r]*(>\s(?<levelSummary>.*))?[\n\r]+(?<levelContent>[^]*))/;
5757
const levelMatch: RegExpMatchArray | null = section.match(levelRegex);
5858
if (levelMatch && levelMatch.groups) {
5959
const {
@@ -67,12 +67,13 @@ export function parseMdContent(md: string): TutorialFrame | never {
6767
mdContent.levels[levelId] = {
6868
id: levelId,
6969
title: levelTitle.trim(),
70-
summary: levelSummary
71-
? levelSummary.trim()
72-
: truncate(levelContent.split(/[\n\r]+/)[0].trim(), {
73-
length: 80,
74-
omission: "...",
75-
}),
70+
summary:
71+
levelSummary && levelSummary.trim().length
72+
? levelSummary.trim()
73+
: truncate(levelContent.split(/[\n\r]+/)[0].trim(), {
74+
length: 80,
75+
omission: "...",
76+
}),
7677
content: levelContent.trim(),
7778
};
7879
current = { level: levelId, step: "0" };

0 commit comments

Comments
 (0)