Skip to content

Fix/summary parse #36

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
Jun 16, 2020
Merged
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
fix empty summary parser issue
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Jun 16, 2020
commit 6c5187c1253e04c2f6136577d7066bea71a65f7c
15 changes: 8 additions & 7 deletions src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(?<levelId>L\d+)\s(?<levelTitle>.*)[\n\r]*(>\s*(?<levelSummary>.*))?[\n\r]+(?<levelContent>[^]*))/;
const levelRegex = /^(#{2}\s(?<levelId>L\d+)\s(?<levelTitle>.*)[\n\r]*(>\s(?<levelSummary>.*))?[\n\r]+(?<levelContent>[^]*))/;
const levelMatch: RegExpMatchArray | null = section.match(levelRegex);
if (levelMatch && levelMatch.groups) {
const {
Expand All @@ -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" };
Expand Down