MCPcopy Index your code
hub / github.com/GitbookIO/gitbook / parseFile

Function parseFile

lib/parse/parseStructureFile.js:13–45  ·  view source on GitHub ↗

Parse a ParsableFile using a specific method @param {FS} fs @param {ParsableFile} file @param {String} type @return {Promise >}

(fs, file, type)

Source from the content-addressed store, hash-verified

11 @return {Promise<Array<String, List|Map>>}
12*/
13function parseFile(fs, file, type) {
14 var filepath = file.getPath();
15 var parser = file.getParser();
16
17 if (!parser) {
18 return Promise.reject(
19 error.FileNotParsableError({
20 filename: filepath
21 })
22 );
23 }
24
25 return fs.readAsString(filepath)
26 .then(function(content) {
27 if (type === 'readme') {
28 return parser.parseReadme(content);
29 } else if (type === 'glossary') {
30 return parser.parseGlossary(content);
31 } else if (type === 'summary') {
32 return parser.parseSummary(content);
33 } else if (type === 'langs') {
34 return parser.parseLanguages(content);
35 } else {
36 throw new Error('Parsing invalid type "' + type + '"');
37 }
38 })
39 .then(function(result) {
40 return [
41 file,
42 result
43 ];
44 });
45}
46
47
48/**

Callers 1

parseStructureFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…