MCPcopy
hub / github.com/braziljs/eloquente-javascript / addSolution

Function addSolution

src/chapter_info.mjs:32–50  ·  view source on GitHub ↗
(name, file, type, num, startCode)

Source from the content-addressed store, hash-verified

30 chapter.links = (zip ? [zip] : []).concat(extraLinks || []);
31
32 function addSolution(name, file, type, num, startCode) {
33 let solution, extra
34 try {
35 solution = fs.readFileSync("code/solutions/" + file, "utf8");
36 extra = /^\s*<!doctype html>\s*(<base .*\n(<script src=.*\n)*)?/.exec(solution);
37 if (extra) solution = solution.slice(extra[0].length);
38 } catch(e) {
39 console.error("File ", file, " does not exist.", e);
40 failed = true;
41 }
42 chapter.exercises.push({
43 name,
44 file: "code/solutions/" + file,
45 number: num,
46 type: type,
47 code: type == "html" ? prepareHTML(startCode, includes) : startCode,
48 solution: type == "html" ? prepareHTML(solution.trim(), includes) : solution.trim()
49 });
50 }
51
52 let exerciseSection = text.indexOf("\n## Exercises\n");
53 let exerciseBlock = exerciseSection >= 0 ? text.slice(exerciseSection) : "";

Callers 1

chapter_info.mjsFile · 0.85

Calls 3

prepareHTMLFunction · 0.85
sliceMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected