@@ -34,6 +34,9 @@ export default class IMEX {
3434 case 'csv' :
3535 return this . _expcsv ( ) ;
3636 break ;
37+ case 'md' :
38+ return this . _expmd ( ) ;
39+ break ;
3740 default :
3841 return false ;
3942 }
@@ -125,11 +128,9 @@ export default class IMEX {
125128 } ) ;
126129
127130 var filters = new Array ( ) ;
128- this . data . forEach ( function ( e ) {
129- filters . push ( {
130- name : e . dialogOptions . name ,
131- extensions : e . dialogOptions . extensions
132- } ) ;
131+ filters . push ( {
132+ name : config . dialogOptions . name ,
133+ extensions : config . dialogOptions . extensions
133134 } ) ;
134135 filters . push ( { name : 'Any File' , extensions : [ '*' ] } ) ;
135136
@@ -154,6 +155,58 @@ export default class IMEX {
154155 }
155156 }
156157
158+ _expmd ( ) {
159+ var storage = this . store ;
160+ var config = this . data . filter ( function ( e ) {
161+ if ( e . name === 'md' ) {
162+ return true ;
163+ } else {
164+ return false ;
165+ }
166+ } ) [ 0 ] ;
167+ var files = storage . retrieveFiles ( ) ;
168+ var md_string = '' ;
169+
170+ if ( files . length > 0 ) {
171+ files . forEach ( function ( element , index , array ) {
172+ var snippet = new Snippet ( JSON . parse ( storage . retrieveFile ( element . replace ( '.json' , '' ) ) ) ) ;
173+ config . order . forEach ( function ( e , i , a ) {
174+ md_string += config . labels [ i ] . prefix ;
175+ md_string += snippet . _get ( e ) ;
176+ md_string += config . labels [ i ] . suffix ;
177+ md_string += config . divider . field ;
178+ } ) ;
179+ md_string += config . divider . line ;
180+ } ) ;
181+
182+ var filters = new Array ( ) ;
183+ filters . push ( {
184+ name : config . dialogOptions . name ,
185+ extensions : config . dialogOptions . extensions
186+ } ) ;
187+ filters . push ( { name : 'Any File' , extensions : [ '*' ] } ) ;
188+
189+ dialog . showSaveDialog ( {
190+ buttonLabel : 'Export' ,
191+ filters : filters
192+ } , function ( filename ) {
193+ if ( Util . isset ( filename , 'string' ) ) {
194+ fs . writeFileSync ( filename , md_string ) ;
195+ if ( fs . existsSync ( filename ) ) {
196+ atom . notifications . addSuccess ( 'Successfully exported the local storage to chosen location.' , null ) ;
197+ return true ;
198+ } else {
199+ atom . notifications . addError ( 'An Error occured while exporting the local storage.' , null ) ;
200+ return false ;
201+ }
202+ }
203+ } ) ;
204+ } else {
205+ atom . notifications . addWarning ( 'The local storage is empty, therefore it can\'t be exported.' , options )
206+ return false ;
207+ }
208+ }
209+
157210 _impcsv ( filename ) {
158211 var storage = this . store ;
159212 var config = this . data . filter ( function ( e ) {
0 commit comments