diff --git a/src/core/fresh-resume.js b/src/core/fresh-resume.js index 821ad6e..6446f4a 100644 --- a/src/core/fresh-resume.js +++ b/src/core/fresh-resume.js @@ -11,6 +11,7 @@ Definition of the FRESHResume class. , _ = require('underscore') , PATH = require('path') , moment = require('moment') + , MD = require('marked') , CONVERTER = require('./convert'); /** @@ -70,6 +71,41 @@ Definition of the FRESHResume class. return JSON.stringify( obj, replacer, 2 ); }, + /** + + */ + FreshResume.prototype.markdownify = function() { + + var that = this; + var ret = extend(true, { }, this); + + // TODO: refactor recursion + function markdownifyStringsInObject( obj ) { + + if( !obj ) return; + if( Object.prototype.toString.call( obj ) === '[object Array]' ) { + obj.forEach(function(elem){ + markdownifyStringsInObject( elem ); + }); + } + else if (typeof obj === 'object') { + if( obj._isAMomentObject || obj.safe ) + return; + Object.keys( obj ).forEach(function(key) { + var sub = obj[key]; + if( typeof sub === 'string' || sub instanceof String ) + obj[key] = MD( obj[key] ); + }); + } + } + + Object.keys( ret ).forEach(function(member){ + markdownifyStringsInObject( that[ member ] ); + }); + + return ret; + }; + /** Convert this object to a JSON string, sanitizing meta-properties along the way. Don't override .toString(). diff --git a/src/eng/underscore-generator.js b/src/eng/underscore-generator.js index d25089d..a560dd6 100644 --- a/src/eng/underscore-generator.js +++ b/src/eng/underscore-generator.js @@ -18,25 +18,15 @@ Underscore template generate for FluentCV. } _.templateSettings = delims; - // Convert {{ someVar }} to {% print(filt.out(someVar) %} - // Convert {{ someVar|someFilter }} to {% print(filt.someFilter(someVar) %} - jst = jst.replace( delims.interpolate, function replace(m, p1) { - if( p1.indexOf('|') > -1 ) { - var terms = p1.split('|'); - return '[~ print( filt.' + terms[1] + '( ' + terms[0] + ' )) ~]'; - } - else { - return '[~ print( filt.out(' + p1 + ') ) ~]'; - } - }); - // Strip {# comments #} jst = jst.replace( delims.comment, ''); // Compile and run the template. TODO: avoid unnecessary recompiles. var compiled = _.template(jst); + var mr = json.markdownify(); + var ret = compiled({ - r: json, + r: json.markdownify(), filt: opts.filters, cssInfo: cssInfo, headFragment: opts.headFragment || ''