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

Feature/markdown as master#48

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 17 commits intomasterfromfeature/markdown-as-master
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
504103a
setup tests
ShMcKJun 21, 2020
8ba4877
update markdown validation
ShMcKJun 21, 2020
67bdfd7
test/update commit order
ShMcKJun 21, 2020
8af3bf6
update parser progress
ShMcKJun 21, 2020
4bb28b9
passing step tests
ShMcKJun 21, 2020
b0d2369
complete parser tests
ShMcKJun 21, 2020
5dd69ce
remove commit validation in skeleton
ShMcKJun 21, 2020
791212e
make step solution optional
ShMcKJun 21, 2020
67b0195
fix multiple commit order issue
ShMcKJun 21, 2020
8558b8e
fix step commit parsing
ShMcKJun 21, 2020
692cb66
setup commit parsing for testing
ShMcKJun 23, 2020
deba9b3
parse commits with tests
ShMcKJun 23, 2020
f6159c4
validate commits
ShMcKJun 24, 2020
0765174
validate step has tests && tests before solution
ShMcKJun 24, 2020
1b7d20b
update step ids
ShMcKJun 24, 2020
325ba8b
update docs for new build format
ShMcKJun 24, 2020
aa745f9
prepare release
ShMcKJun 24, 2020
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
NextNext commit
update parser progress
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
@ShMcK
ShMcK committedJun 21, 2020
commit8af3bf6a683e08f8c2e1cc96e8a9f221aa140cf9
170 changes: 85 additions & 85 deletionssrc/utils/parse.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,10 +4,7 @@ import * as T from "../../typings/tutorial";

type TutorialFrame = {
summary: T.TutorialSummary;
levels: {
[levelKey: string]: T.Level;
};
steps: { [stepKey: string]: Partial<T.Step> };
levels: T.Level[];
};

export function parseMdContent(md: string): TutorialFrame | never {
Expand All@@ -33,8 +30,7 @@ export function parseMdContent(md: string): TutorialFrame | never {
title: "",
description: "",
},
levels: {},
steps: {},
levels: [],
};

// Capture summary
Expand All@@ -49,23 +45,20 @@ export function parseMdContent(md: string): TutorialFrame | never {
mdContent.summary.description = summaryMatch.groups.tutorialDescription.trim();
}

let current = { level:"0", step:"0" };
let current = { level:-1, step:0 };
// 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 {
levelId,
levelTitle,
levelSummary,
levelContent,
} = levelMatch.groups;
current = { level: current.level + 1, step: 0 };
const { levelTitle, levelSummary, levelContent } = levelMatch.groups;

// @ts-ignore
mdContent.levels[levelId] = {
id:levelId,
mdContent.levels[current.level] = {
id:(current.level + 1).toString(),
title: levelTitle.trim(),
summary:
levelSummary && levelSummary.trim().length
Expand All@@ -75,20 +68,21 @@ export function parseMdContent(md: string): TutorialFrame | never {
omission: "...",
}),
content: levelContent.trim(),
steps: [],
};
current = { level: levelId, step: "0" };
} else {
// match step
const stepRegex = /^(#{3}\s(?<stepId>(?<levelId>L\d+)S\d+)\s(?<stepTitle>.*)[\n\r]+(?<stepContent>[^]*))/;
const stepRegex = /^(#{3}\s\(?<stepTitle>.*)[\n\r]+(?<stepContent>[^]*)/;
const stepMatch: RegExpMatchArray | null = section.match(stepRegex);
if (stepMatch && stepMatch.groups) {
const { stepId, stepContent } = stepMatch.groups;

mdContent.steps[stepId] = {
mdContent.levels[current.level].steps[current.step] = {
id: stepId,
content: stepContent.trim(),
setup: {},
solution: {},
};
current = { ...current, step:stepId };
current = { ...current, step:current.step + 1 };
} else {
// parse hints from stepContent
const hintDetectRegex = /^(#{4}\sHINTS[\n\r]+(\*\s(?<hintContent>[^]*))[\n\r]+)+/;
Expand All@@ -100,7 +94,7 @@ export function parseMdContent(md: string): TutorialFrame | never {
.slice(1) // remove #### HINTS
.map((h) => h.trim());
if (hints.length) {
mdContent.steps[current.step].hints = hints;
mdContent.levels[current.level].steps[current.step].hints = hints;
}
}
}
Expand DownExpand Up@@ -135,72 +129,78 @@ export function parse(params: ParseParams): any {
};
}

// merge content and tutorial
if (params.skeleton.levels && params.skeleton.levels.length) {
parsed.levels = params.skeleton.levels
.map((level: T.Level, levelIndex: number) => {
const levelContent = mdContent.levels[level.id];
// merge content levels and tutorial

if (!levelContent) {
return null;
}

level = { ...level, ...levelContent };

// add level setup commits
const levelSetupKey = level.id;
if (params.commits[levelSetupKey]) {
level.setup = {
...(level.setup || {}),
commits: params.commits[levelSetupKey],
};
}
parsed.levels = mdContent.levels.map((level: T.Level, levelIndex: number) => {
// add level setup commits
const levelId = level.id;
if (params.commits[levelId]) {
if (!level.setup) {
level.setup = {};
}
level.setup.commits = params.commits[levelId];
}

// add level step commits
try {
level.steps = (level.steps || []).map(
(step: T.Step, stepIndex: number) => {
const stepKey = `${levelSetupKey}S${stepIndex + 1}`;
const stepSetupKey = `${stepKey}Q`;
if (params.commits[stepSetupKey]) {
if (!step.setup) {
step.setup = {
commits: [],
};
}
step.setup.commits = params.commits[stepSetupKey];
}

const stepSolutionKey = `${stepKey}A`;
if (params.commits[stepSolutionKey]) {
if (!step.solution) {
step.solution = {
commits: [],
};
}
step.solution.commits = params.commits[stepSolutionKey];
}

// add markdown
const stepMarkdown: Partial<T.Step> = mdContent.steps[step.id];
if (stepMarkdown) {
step = { ...step, ...stepMarkdown };
}

step.id = `${stepKey}`;
return step;
}
);
} catch (error) {
console.log(JSON.stringify(level.steps));
console.error("Error parsing level steps");
console.error(error.message);
}
// get yaml for level
const configLevel = params.skeleton.levels.find(
(l: Partial<T.Level>) => l.id === levelId
);

let configSteps = {};
if (configLevel) {
const { steps, ...configLevelProps } = configLevel;
level = { ...configLevelProps, ...level };
if (steps) {
steps.forEach((s: T.Step) => {
configSteps[s.id] = s;
});
}
}

return level;
})
.filter((l: T.Level | null) => !!l);
}
// add level step commits
// try {
// level.steps = (level.steps || []).map(
// (step: T.Step, stepIndex: number) => {
// const stepKey = `${levelId}S${stepIndex + 1}`;
// const stepSetupKey = `${stepKey}Q`;
// if (params.commits[stepSetupKey]) {
// if (!step.setup) {
// step.setup = {
// commits: [],
// };
// }
// step.setup.commits = params.commits[stepSetupKey];
// }

// const stepSolutionKey = `${stepKey}A`;
// if (params.commits[stepSolutionKey]) {
// if (!step.solution) {
// step.solution = {
// commits: [],
// };
// }
// step.solution.commits = params.commits[stepSolutionKey];
// }

// // add markdown
// const stepMarkdown: Partial<T.Step> =
// mdContent.levels[level.id].steps[step.id];
// if (stepMarkdown) {
// step = { ...step, ...stepMarkdown };
// }

// step.id = `${stepKey}`;
// return step;
// }
// );
// } catch (error) {
// console.log(JSON.stringify(level.steps));
// console.error("Error parsing level steps");
// console.error(error.message);
// }

return level;
});

return parsed;
}
22 changes: 11 additions & 11 deletionstests/parse.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,7 @@ Short description to be shown as a tutorial's subtitle.

Description.

## Put Level's title here
##1.Put Level's title here

> Level's summary: a short description of the level's content in one line.

Expand DownExpand Up@@ -68,7 +68,7 @@ Some text

Description.

## Put Level's title here
##1.Put Level's title here

> Level's summary: a short description of the level's content in one line.

Expand DownExpand Up@@ -112,7 +112,7 @@ Some text

Description.

## Put Level's title here
##1.Put Level's title here

Some text that becomes the summary
`;
Expand DownExpand Up@@ -142,7 +142,7 @@ Some text that becomes the summary

Description.

## Put Level's title here
##1.Put Level's title here

Some text that becomes the summary and goes beyond the maximum length of 80 so that it gets truncated at the end
`;
Expand DownExpand Up@@ -171,7 +171,7 @@ Some text that becomes the summary and goes beyond the maximum length of 80 so t

Description.

## 1 Put Level's title here
## 1. Put Level's title here

Some text.

Expand DownExpand Up@@ -203,7 +203,7 @@ But not including this line.

Description.

## Put Level's title here
##1.Put Level's title here

>

Expand DownExpand Up@@ -239,7 +239,7 @@ Description.

Second description line

## Titles
##1.Titles

First line

Expand DownExpand Up@@ -275,7 +275,7 @@ Third line

Description.

## Title
##1.Title

First line

Expand DownExpand Up@@ -331,7 +331,7 @@ The first step

Description.

## Title
##1.Title

First line

Expand DownExpand Up@@ -387,7 +387,7 @@ The first step

Description.

## Title
##1.Title

First line

Expand DownExpand Up@@ -935,7 +935,7 @@ Description.
});
});

describe("hints", () => {
xdescribe("hints", () => {
it("should parse hints for a step", () => {
const md = `# Title

Expand Down
2 changes: 1 addition & 1 deletiontypings/tutorial.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,7 @@ export type TutorialSummary = {

export type StepActions = {
commands?: string[];
commits: string[];
commits?: string[];
files?: string[];
watchers?: string[];
filter?: string;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp