@@ -37,41 +37,42 @@ var annotations_exporter = function (pl) {
37
37
return oldAnnotationsJSON . comments ;
38
38
}
39
39
40
- /*
41
- Converts the annotations.md file yaml list into an array of annotations
42
- */
43
- function parseAnnotationsMD ( ) {
44
- var markdown_parser = new mp ( ) ;
45
- var annotations = [ ] ;
46
- var mdFiles = readDir . readSync ( paths . source . annotations , [ '*.md' ] )
40
+ function buildAnnotationMD ( annotationsYAML , markdown_parser ) {
41
+ var annotation = { } ;
42
+ var markdownObj = markdown_parser . parse ( annotationsYAML ) ;
43
+
44
+ annotation . el = markdownObj . el || markdownObj . selector ;
45
+ annotation . title = markdownObj . title ;
46
+ annotation . comment = markdownObj . markdown ;
47
+ return annotation ;
48
+ }
47
49
48
- mdFiles . forEach ( function ( file ) {
49
- var annotationsMD = '' ;
50
- try {
51
- annotationsMD = fs . readFileSync ( path . resolve ( paths . source . annotations , file ) , '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
- }
50
+ function parseMDFile ( annotations , parser ) {
51
+ var annotations = annotations ;
52
+ var markdown_parser = parser ;
53
+
54
+ return function ( file ) {
55
+ var annotationsMD = fs . readFileSync ( path . resolve ( paths . source . annotations , file ) , 'utf8' ) ;
58
56
59
57
//take the annotation snippets and split them on our custom delimiter
60
58
var annotationsYAML = annotationsMD . split ( '~*~' ) ;
61
-
62
59
for ( var i = 0 ; i < annotationsYAML . length ; i ++ ) {
63
- var annotation = { } ;
64
-
65
- var markdownObj = markdown_parser . parse ( annotationsYAML [ i ] ) ;
66
-
67
- annotation . el = markdownObj . el || markdownObj . selector ;
68
- annotation . title = markdownObj . title ;
69
- annotation . comment = markdownObj . markdown ;
70
-
60
+ var annotation = buildAnnotationMD ( annotationsYAML [ i ] , markdown_parser )
71
61
annotations . push ( annotation ) ;
72
62
}
73
63
return false ;
74
- } )
64
+ }
65
+ }
66
+
67
+ /*
68
+ Converts the *.md file yaml list into an array of annotations
69
+ */
70
+ function parseAnnotationsMD ( ) {
71
+ var markdown_parser = new mp ( ) ;
72
+ var annotations = [ ] ;
73
+ var mdFiles = readDir . readSync ( paths . source . annotations , [ '*.md' ] )
74
+
75
+ mdFiles . forEach ( parseMDFile ( annotations , markdown_parser ) ) ;
75
76
return annotations ;
76
77
}
77
78
0 commit comments