1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 09:56:22 +00:00

Support basic Markdown in MS Word docs.

This commit is contained in:
devlinjd 2015-12-16 23:26:53 -05:00
parent ae9c295ce1
commit 5475b081b1
3 changed files with 79 additions and 6 deletions

View File

@ -9,6 +9,8 @@ Handlebars template generate for FluentCV.
var HANDLEBARS = require('handlebars');
var FS = require('fs');
var moment = require('moment');
var MD = require('marked');
var H2W = require('../utils/html-to-wpml');
module.exports = function( json, jst, format, cssInfo, opts, theme ) {
@ -27,6 +29,13 @@ Handlebars template generate for FluentCV.
}
});
HANDLEBARS.registerHelper("wpml", function( txt, inline ) {
inline = (inline && !inline.hash) || false;
txt = inline ? MD(txt.trim()).replace(/^\s*<p>|<\/p>\s*$/gi, '') : MD(txt.trim());
txt = H2W( txt.trim() );
return txt;
});
// http://doginthehat.com.au/2012/02/comparison-block-helper-for-handlebars-templates/
HANDLEBARS.registerHelper('compare', function(lvalue, rvalue, options) {

View File

@ -3,11 +3,16 @@ MS Word resume generator for FluentCV.
@license Copyright (c) 2015 by James M. Devlin. All rights reserved.
*/
var TemplateGenerator = require('./template-generator');
var WordGenerator = module.exports = TemplateGenerator.extend({
(function() {
init: function(){
this._super( 'doc', 'xml' );
}
var TemplateGenerator = require('./template-generator');
var WordGenerator = module.exports = TemplateGenerator.extend({
});
init: function(){
this._super( 'doc', 'xml' );
}
});
}());

59
src/utils/html-to-wpml.js Normal file
View File

@ -0,0 +1,59 @@
(function(){
var _ = require('underscore');
var HTML5Tokenizer = require('simple-html-tokenizer');
module.exports = function( html ) {
var final = '';
var is_bold = false, is_italic = false;
var depth = 0;
var tokens = HTML5Tokenizer.tokenize( html );
_.each( tokens, function( tok ) {
switch( tok.type ) {
case 'StartTag':
switch( tok.tagName ) {
case 'p':
final += '<w:p>';
break;
case 'strong':
is_bold = true;
break;
case 'em':
is_italic = true;
break;
case 'a':
is_link = true;
break;
}
break;
case 'EndTag':
switch( tok.tagName ) {
case 'p':
final += '</w:p>';
break;
case 'strong':
is_bold = false;
break;
case 'em':
is_italic = false;
break;
case 'a':
is_link = false;
break;
}
break;
case 'Chars':
var style = is_bold ? '<w:b/>' : '';
style += is_italic ? '<w:i/>': '';
final += '<w:r><w:rPr>' + style + '</w:rPr><w:t>' + tok.chars + '</w:t></w:r>';
break;
}
});
return final;
};
}());