Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 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
Prev Previous commit
Next Next commit
parse hints
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed Jun 7, 2020
commit 52eafafcfcba24aafdd68a23e418442351021403
24 changes: 17 additions & 7 deletions src/utils/parse.ts
Original file line number Diff line number Diff 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 deletions tests/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ Description.
});
});

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

Expand Down Expand 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 Down Expand 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 Down Expand 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 deletions typings/tutorial.d.ts
Original file line number Diff line number Diff 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