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 from1 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
PrevPrevious commit
handle levels out of order
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
@ShMcK
ShMcK committedJun 25, 2020
commitab93ee538a5ded4e0c9d6689813723c18d9309b4
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
17 changes: 10 additions & 7 deletionstests/parse.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -842,29 +842,29 @@ The first step

Description.

## 100. Title
## 100.FirstTitle

First line

### 100.1

The first step

## 200. Title
## 200.SecondTitle

First line
Second line

### 200.1

Thefirst step
Thesecond step

## 201. Title
## 201.ThirdTitle

First line
Third line

### 201.1

Thefirst step
Thethird step
`;
const skeleton = {
levels: [
Expand DownExpand Up@@ -894,6 +894,7 @@ The first step
levels: [
{
id: "100",
title: "First Title",
summary: "First line",
content: "First line",
steps: [
Expand All@@ -908,6 +909,7 @@ The first step
},
{
id: "200",
title: "Second Title",
summary: "Second line",
content: "Second line",
steps: [
Expand All@@ -922,6 +924,7 @@ The first step
},
{
id: "201",
title: "Third Title",
summary: "Third line",
content: "Third line",
steps: [
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp