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
run multi-line step test
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed Jun 7, 2020
commit 142a047fc2e613f539b9da19f85f7cb7ccf70d7a
74 changes: 44 additions & 30 deletions src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function parseMdContent(md: string): TutorialFrame | never {
// Identify each part of the content
parts.forEach((section: string) => {
// match level
const levelRegex = /^(##\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 {
Expand All @@ -73,10 +73,18 @@ export function parseMdContent(md: string): TutorialFrame | never {
};
} else {
// match step
const stepRegex = /^(###\s(?<stepId>(?<levelId>L\d+)S\d+)\s(?<stepTitle>.*)[\n\r]+(?<stepContent>[^]*))/;
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(),
Expand Down Expand Up @@ -135,39 +143,45 @@ export function parse(params: ParseParams): any {
}

// add level step commits
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: [],
};
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];
}
step.setup.commits = params.commits[stepSetupKey];
}

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

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

step.id = `${stepKey}`;
return step;
}
);
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;
})
Expand Down
Loading