mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-12-23 13:47:22 +00:00
Improve Markdown support for JSON Resume themes.
This commit is contained in:
parent
02ef2b2241
commit
483207e5a0
@ -11,6 +11,7 @@ Definition of the JRSResume class.
|
||||
, validator = require('is-my-json-valid')
|
||||
, _ = require('underscore')
|
||||
, PATH = require('path')
|
||||
, MD = require('marked')
|
||||
, moment = require('moment');
|
||||
|
||||
/**
|
||||
@ -238,6 +239,70 @@ Definition of the JRSResume class.
|
||||
|
||||
};
|
||||
|
||||
JRSResume.prototype.dupe = function() {
|
||||
var rnew = new JRSResume();
|
||||
rnew.parse( this.stringify(), { } );
|
||||
return rnew;
|
||||
};
|
||||
|
||||
/**
|
||||
Create a copy of this resume in which all fields have been interpreted as
|
||||
Markdown.
|
||||
*/
|
||||
JRSResume.prototype.harden = function() {
|
||||
|
||||
var that = this;
|
||||
var ret = this.dupe();
|
||||
|
||||
function HD(txt) {
|
||||
return '@@@@~' + txt + '~@@@@';
|
||||
}
|
||||
|
||||
function HDIN(txt){
|
||||
//return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
|
||||
return HD(txt);
|
||||
}
|
||||
|
||||
// TODO: refactor recursion
|
||||
function hardenStringsInObject( obj, inline ) {
|
||||
|
||||
if( !obj ) return;
|
||||
inline = inline === undefined || inline;
|
||||
|
||||
|
||||
if( Object.prototype.toString.call( obj ) === '[object Array]' ) {
|
||||
obj.forEach(function(elem, idx, ar){
|
||||
if( typeof elem === 'string' || elem instanceof String )
|
||||
ar[idx] = inline ? HDIN(elem) : HD( elem );
|
||||
else
|
||||
hardenStringsInObject( elem );
|
||||
});
|
||||
}
|
||||
else if (typeof obj === 'object') {
|
||||
Object.keys( obj ).forEach(function(key) {
|
||||
var sub = obj[key];
|
||||
if( typeof sub === 'string' || sub instanceof String ) {
|
||||
if( _.contains(['skills','url','website','startDate','endDate','releaseDate','date','phone','email','address','postalCode','city','country','region'], key) )
|
||||
return;
|
||||
if( key === 'summary' )
|
||||
obj[key] = HD( obj[key] );
|
||||
else
|
||||
obj[key] = inline ? HDIN( obj[key] ) : HD( obj[key] );
|
||||
}
|
||||
else
|
||||
hardenStringsInObject( sub );
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Object.keys( ret ).forEach(function(member){
|
||||
hardenStringsInObject( ret[ member ] );
|
||||
});
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
Convert human-friendly dates into formal Moment.js dates for all collections.
|
||||
We don't want to lose the raw textual date as entered by the user, so we store
|
||||
|
@ -3,6 +3,7 @@
|
||||
var PATH = require('path')
|
||||
, FS = require('fs')
|
||||
, parsePath = require('parse-filepath')
|
||||
, MD = require('marked')
|
||||
, MKDIRP = require('mkdirp')
|
||||
, _opts = require('../core/default-options')
|
||||
, FluentTheme = require('../core/theme')
|
||||
@ -102,6 +103,11 @@
|
||||
"/foo/bar/resume.pdf" or "c:\foo\bar\resume.txt".
|
||||
*/
|
||||
function single( targInfo, theme ) {
|
||||
|
||||
function MDIN(txt) {
|
||||
return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
|
||||
}
|
||||
|
||||
try {
|
||||
var f = targInfo.file
|
||||
, fType = targInfo.fmt.outFormat
|
||||
@ -144,7 +150,24 @@
|
||||
// return PATH.join(p2, p1);
|
||||
// }
|
||||
});
|
||||
var rezHtml = theme.render( rez );
|
||||
|
||||
// Prevent JSON Resume theme .js from chattering
|
||||
var consoleLog = console.log;
|
||||
console.log = function() { };
|
||||
|
||||
// Call the theme's render method
|
||||
var rezDupe = rez.harden();
|
||||
var rezHtml = theme.render( rezDupe );
|
||||
|
||||
// Turn logging back on
|
||||
console.log = consoleLog;
|
||||
|
||||
// Unharden
|
||||
rezHtml = rezHtml.replace( /@@@@~.+?~@@@@/g, function(val){
|
||||
return MDIN( val.replace( /~@@@@/gm,'' ).replace( /@@@@~/gm,'' ) );
|
||||
});
|
||||
|
||||
// Save the file
|
||||
FS.writeFileSync( f, rezHtml );
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user