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