diff --git a/src/eng/handlebars-generator.js b/src/eng/handlebars-generator.js index fba7bd0..ef61ed5 100644 --- a/src/eng/handlebars-generator.js +++ b/src/eng/handlebars-generator.js @@ -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>\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) { diff --git a/src/gen/word-generator.js b/src/gen/word-generator.js index c48918a..0ca3f01 100644 --- a/src/gen/word-generator.js +++ b/src/gen/word-generator.js @@ -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' ); + } + + }); + + +}()); diff --git a/src/utils/html-to-wpml.js b/src/utils/html-to-wpml.js new file mode 100644 index 0000000..b0136ef --- /dev/null +++ b/src/utils/html-to-wpml.js @@ -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 += ''; + 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 += ''; + 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 ? '' : ''; + style += is_italic ? '': ''; + final += '' + style + '' + tok.chars + ''; + break; + } + }); + return final; + + }; + +}());