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

Function getStartCode

src/chapter_info.mjs:202–218  ·  view source on GitHub ↗
(text, includes)

Source from the content-addressed store, hash-verified

200}
201
202function getStartCode(text, includes) {
203 let found = /\n```(.*?\bstartCode:.*)\n([^]*?\n)```/.exec(text);
204 if (!found) return ""
205
206 let snippet = found[2].replace(/(\n|^)\s*\/\/ →.*\n/g, "$1");
207 let directive = String(PJSON.parse(found[1]).startCode), m;
208 if (m = directive.match(/top_lines:\s*(\d+)/))
209 snippet = snippet.split("\n").slice(0, Number(m[1])).join("\n") + "\n";
210 if (m = directive.match(/bottom_lines:\s*(\d+)/)) {
211 let lines = snippet.trimRight().split("\n");
212 snippet = lines.slice(lines.length - Number(m[1])).join("\n") + "\n";
213 }
214 if (guessType(snippet) == "html")
215 return prepareHTML(snippet, includes);
216 else
217 return snippet;
218}
219
220function chapterZipFile(meta, chapter) {
221 let spec = meta.match(/\bzip: ("(?:\\.|[^"\\])*")/);

Callers 1

chapter_info.mjsFile · 0.85

Calls 8

prepareHTMLFunction · 0.85
matchMethod · 0.80
guessTypeFunction · 0.70
replaceMethod · 0.45
parseMethod · 0.45
joinMethod · 0.45
sliceMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected