|
1 | 1 | "use strict"; |
2 | 2 |
|
3 | 3 | var path = require('path'), |
| 4 | + glob = require('glob'), |
4 | 5 | fs = require('fs-extra'), |
5 | 6 | JSON5 = require('json5'), |
6 | 7 | _ = require('lodash'), |
@@ -38,38 +39,42 @@ var annotations_exporter = function (pl) { |
38 | 39 | return oldAnnotationsJSON.comments; |
39 | 40 | } |
40 | 41 |
|
41 | | - /* |
42 | | - Converts the annotations.md file yaml list into an array of annotations |
43 | | - */ |
44 | | - function parseAnnotationsMD() { |
45 | | - var markdown_parser = new mp(); |
46 | | - var annotations = []; |
| 42 | + function buildAnnotationMD(annotationsYAML, markdown_parser) { |
| 43 | + var annotation = {}; |
| 44 | + var markdownObj = markdown_parser.parse(annotationsYAML); |
47 | 45 |
|
48 | | - //attempt to read the file |
49 | | - var annotationsMD = ''; |
50 | | - try { |
51 | | - annotationsMD = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.md'), 'utf8'); |
52 | | - } catch (ex) { |
53 | | - if (pl.config.debug) { |
54 | | - console.log('annotations.md file missing from ' + paths.source.annotations + '. This may be expected.'); |
55 | | - } |
56 | | - return []; |
57 | | - } |
| 46 | + annotation.el = markdownObj.el || markdownObj.selector; |
| 47 | + annotation.title = markdownObj.title; |
| 48 | + annotation.comment = markdownObj.markdown; |
| 49 | + return annotation; |
| 50 | + } |
58 | 51 |
|
59 | | - //take the annotation snippets and split them on our custom delimiter |
60 | | - var annotationsYAML = annotationsMD.split('~*~'); |
| 52 | + function parseMDFile(annotations, parser) { |
| 53 | + var annotations = annotations; |
| 54 | + var markdown_parser = parser; |
61 | 55 |
|
62 | | - for (var i = 0; i < annotationsYAML.length; i++) { |
63 | | - var annotation = {}; |
| 56 | + return function (filePath) { |
| 57 | + var annotationsMD = fs.readFileSync(path.resolve(filePath), 'utf8'); |
64 | 58 |
|
65 | | - var markdownObj = markdown_parser.parse(annotationsYAML[i]); |
| 59 | + //take the annotation snippets and split them on our custom delimiter |
| 60 | + var annotationsYAML = annotationsMD.split('~*~'); |
| 61 | + for (var i = 0; i < annotationsYAML.length; i++) { |
| 62 | + var annotation = buildAnnotationMD(annotationsYAML[i], markdown_parser) |
| 63 | + annotations.push(annotation); |
| 64 | + } |
| 65 | + return false; |
| 66 | + } |
| 67 | + } |
66 | 68 |
|
67 | | - annotation.el = markdownObj.el || markdownObj.selector; |
68 | | - annotation.title = markdownObj.title; |
69 | | - annotation.comment = markdownObj.markdown; |
| 69 | + /* |
| 70 | + Converts the *.md file yaml list into an array of annotations |
| 71 | + */ |
| 72 | + function parseAnnotationsMD() { |
| 73 | + var markdown_parser = new mp(); |
| 74 | + var annotations = []; |
| 75 | + var mdFiles = glob.sync(paths.source.annotations + '/*.md') |
70 | 76 |
|
71 | | - annotations.push(annotation); |
72 | | - } |
| 77 | + mdFiles.forEach(parseMDFile(annotations, markdown_parser)); |
73 | 78 | return annotations; |
74 | 79 | } |
75 | 80 |
|
|
0 commit comments