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/id order#52

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 3 commits intomasterfromfix/id-order
Jun 25, 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
2 changes: 1 addition & 1 deletionpackage-lock.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

2 changes: 1 addition & 1 deletionpackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
{
"name": "@coderoad/cli",
"version": "0.4.2",
"version": "0.4.3",
"description": "A CLI to build the configuration file for Coderoad Tutorials",
"keywords": [
"coderoad",
Expand Down
27 changes: 19 additions & 8 deletionssrc/utils/parse.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,20 +45,25 @@ export function parseMdContent(md: string): TutorialFrame | never {
mdContent.summary.description = summaryMatch.groups.tutorialDescription.trim();
}

let current = {level:-1,step: -1 };
let current = {levelId: "", levelIndex:-1,stepIndex: -1 };
// 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 levelMatch: RegExpMatchArray | null = section.match(levelRegex);

if (levelMatch && levelMatch.groups) {
current = { level: current.level + 1, step: -1 };
const levelId = levelMatch.groups.levelId.replace(".", "");
current = {
levelId: levelId,
levelIndex: current.levelIndex + 1,
stepIndex: -1,
};
const { levelTitle, levelSummary, levelContent } = levelMatch.groups;

// @ts-ignore
mdContent.levels[current.level] = {
id:(current.level + 1).toString(),
mdContent.levels[current.levelIndex] = {
id:levelId,
title: levelTitle.trim(),
summary:
levelSummary && levelSummary.trim().length
Expand All@@ -75,10 +80,14 @@ export function parseMdContent(md: string): TutorialFrame | never {
const stepRegex = /^(#{3}\s(?<stepTitle>.*)[\n\r]+(?<stepContent>[^]*))/;
const stepMatch: RegExpMatchArray | null = section.match(stepRegex);
if (stepMatch && stepMatch.groups) {
current = { level: current.level, step: current.step + 1 };
current = {
levelId: current.levelId,
levelIndex: current.levelIndex,
stepIndex: current.stepIndex + 1,
};
const { stepId, stepContent } = stepMatch.groups;
mdContent.levels[current.level].steps[current.step] = {
id: `${current.level + 1}.${current.step + 1}`,
mdContent.levels[current.levelIndex].steps[current.stepIndex] = {
id: `${current.levelId}.${current.stepIndex + 1}`,
content: stepContent.trim(),
};
} else {
Expand All@@ -92,7 +101,9 @@ export function parseMdContent(md: string): TutorialFrame | never {
.slice(1) // remove #### HINTS
.map((h) => h.trim());
if (hints.length) {
mdContent.levels[current.level].steps[current.step].hints = hints;
mdContent.levels[current.levelIndex].steps[
current.stepIndex
].hints = hints;
}
}
}
Expand Down
105 changes: 105 additions & 0 deletionstests/parse.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -837,6 +837,111 @@ The first step
});
});

it("should load when commits are not in direct order (100, 200, 201)", () => {
const md = `# Title

Description.

## 100. First Title

First line

### 100.1

The first step

## 200. Second Title

Second line

### 200.1

The second step

## 201. Third Title

Third line

### 201.1

The third step
`;
const skeleton = {
levels: [
{
id: "100",
steps: [{ id: "100.1" }],
},
{
id: "200",
steps: [{ id: "200.1" }],
},
{
id: "201",
steps: [{ id: "201.1" }],
},
],
};
const result = parse({
text: md,
skeleton,
commits: {},
});
const expected = {
summary: {
description: "Description.",
},
levels: [
{
id: "100",
title: "First Title",
summary: "First line",
content: "First line",
steps: [
{
id: "100.1",
content: "The first step",
setup: {
commits: [],
},
},
],
},
{
id: "200",
title: "Second Title",
summary: "Second line",
content: "Second line",
steps: [
{
id: "200.1",
content: "The second step",
setup: {
commits: [],
},
},
],
},
{
id: "201",
title: "Third Title",
summary: "Third line",
content: "Third line",
steps: [
{
id: "201.1",
content: "The third step",
setup: {
commits: [],
},
},
],
},
],
};
expect(result.levels).toEqual(expected.levels);
});

describe("config", () => {
it("should parse the tutorial config", () => {
const md = `# Title
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp