Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 2 commits intomasterfromfix/summary-parse
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes fromall 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
15 changes: 8 additions & 7 deletionssrc/utils/parse.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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
37 changes: 36 additions & 1 deletiontests/parse.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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", () => {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp