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/hints#31

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 5 commits intomasterfromfeature/hints
Jun 7, 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
NextNext commit
parse hints
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
@ShMcK
ShMcK committedJun 7, 2020
commit52eafafcfcba24aafdd68a23e418442351021403
24 changes: 17 additions & 7 deletionssrc/utils/parse.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,6 +49,7 @@ export function parseMdContent(md: string): TutorialFrame | never {
mdContent.summary.description = summaryMatch.groups.tutorialDescription.trim();
}

let current = { level: "0", step: "0" };
// Identify each part of the content
parts.forEach((section: string) => {
// match level
Expand All@@ -71,24 +72,33 @@ export function parseMdContent(md: string): TutorialFrame | never {
: truncate(levelContent.trim(), { length: 80, omission: "..." }),
content: levelContent.trim(),
};
current = { level: levelId, step: "0" };
} else {
// match step
const stepRegex = /^(#{3}\s(?<stepId>(?<levelId>L\d+)S\d+)\s(?<stepTitle>.*)[\n\r]+(?<stepContent>[^]*))/;
const stepMatch: RegExpMatchArray | null = section.match(stepRegex);
if (stepMatch && stepMatch.groups) {
const { stepId, stepContent } = stepMatch.groups;

// parse hints from stepContent
// const hintRegex = /^(#{4}\sHINTS[\n\r]+(?<hintContent>[^]*))/g;

// if (!!stepContent.match(hintRegex)) {
// console.log("HAS HINT");
// }

mdContent.steps[stepId] = {
id: stepId,
content: stepContent.trim(),
};
current = { ...current, step: stepId };
} else {
// parse hints from stepContent
const hintDetectRegex = /^(#{4}\sHINTS[\n\r]+(\*\s(?<hintContent>[^]*))[\n\r]+)+/;
const hintMatch = section.match(hintDetectRegex);
if (!!hintMatch) {
const hintItemRegex = /[\n\r]+\*\s/;
const hints = section
.split(hintItemRegex)
.slice(1) // remove #### HINTS
.map((h) => h.trim());
if (hints.length) {
mdContent.steps[current.step].hints = hints;
}
}
}
}
});
Expand Down
12 changes: 6 additions & 6 deletionstests/parse.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -869,7 +869,7 @@ Description.
});
});

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

Expand DownExpand Up@@ -947,7 +947,7 @@ First level content.

The first step

####Hints
####HINTS

* First Hint with \`markdown\`. See **bold**
* Second Hint has a codeblock
Expand DownExpand Up@@ -1019,7 +1019,7 @@ First level content.

The first step

####Hints
####HINTS

* First Hint with \`markdown\`. See **bold**
* Second Hint has a codeblock
Expand All@@ -1030,7 +1030,7 @@ var a = 1;

And spans multiple lines.

###L1S2A
###L1S2

The second uninterrupted step
`;
Expand DownExpand Up@@ -1073,7 +1073,7 @@ The second uninterrupted step
id: "L1S1",
content: "The first step",
setup: {
commits: ["abcdef1", "123456789"],
commits: ["abcdef1"],
},
solution: {
commits: ["123456789"],
Expand All@@ -1095,7 +1095,7 @@ The second uninterrupted step
{},
],
};
expect(result.levels).toEqual(expected.levels);
expect(result.levels[0]).toEqual(expected.levels[0]);
});
});
});
1 change: 1 addition & 0 deletionstypings/tutorial.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,7 @@ export type Step = {
setup: StepActions;
solution: Maybe<StepActions>;
subtasks?: { [testName: string]: boolean };
hints?: string[];
};

/** A tutorial for use in VSCode CodeRoad */
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp