mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-21 16:00:11 +00:00
Escape LaTeX during generation.
This commit is contained in:
parent
ca92d41d9e
commit
2d595350c6
34
dist/renderers/underscore-generator.js
vendored
34
dist/renderers/underscore-generator.js
vendored
@ -6,12 +6,16 @@ Definition of the UnderscoreGenerator class.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var UnderscoreGenerator, _, registerHelpers;
|
||||
var UnderscoreGenerator, _, escapeLaTeX, registerHelpers;
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
registerHelpers = require('../helpers/underscore-helpers');
|
||||
|
||||
require('../utils/string');
|
||||
|
||||
escapeLaTeX = require('escape-latex');
|
||||
|
||||
|
||||
/**
|
||||
Perform template-based resume generation using Underscore.js.
|
||||
@ -33,7 +37,7 @@ Definition of the UnderscoreGenerator class.
|
||||
}
|
||||
},
|
||||
generate: function(json, jst, format, cssInfo, opts, theme) {
|
||||
var ctx, delims;
|
||||
var ctx, delims, r, traverse;
|
||||
delims = (opts.themeObj && opts.themeObj.delimeters) || opts.template;
|
||||
if (opts.themeObj && opts.themeObj.delimeters) {
|
||||
delims = _.mapObject(delims, function(val, key) {
|
||||
@ -41,9 +45,31 @@ Definition of the UnderscoreGenerator class.
|
||||
});
|
||||
}
|
||||
_.templateSettings = delims;
|
||||
jst = jst.replace(delims.comment, '');
|
||||
r = null;
|
||||
switch (format) {
|
||||
case 'html':
|
||||
r = json.markdownify();
|
||||
break;
|
||||
case 'pdf':
|
||||
r = json.markdownify();
|
||||
break;
|
||||
case 'png':
|
||||
r = json.markdownify();
|
||||
break;
|
||||
case 'latex':
|
||||
traverse = require('traverse');
|
||||
r = traverse(json).map(function(x) {
|
||||
if (this.isLeaf && String.is(this.node)) {
|
||||
return escapeLaTeX(this.node);
|
||||
}
|
||||
return this.node;
|
||||
});
|
||||
break;
|
||||
default:
|
||||
r = json;
|
||||
}
|
||||
ctx = {
|
||||
r: format === 'html' || format === 'pdf' || format === 'png' ? json.markdownify() : json,
|
||||
r: r,
|
||||
filt: opts.filters,
|
||||
XML: require('xml-escape'),
|
||||
RAW: json,
|
||||
|
@ -51,6 +51,7 @@
|
||||
"chalk": "^1.1.1",
|
||||
"commander": "^2.9.0",
|
||||
"copy": "^0.1.3",
|
||||
"escape-latex": "^0.1.2",
|
||||
"extend": "^3.0.0",
|
||||
"fresca": "~0.6.0",
|
||||
"fresh-jrs-converter": "^0.2.2",
|
||||
|
@ -8,8 +8,8 @@ Definition of the UnderscoreGenerator class.
|
||||
|
||||
_ = require 'underscore'
|
||||
registerHelpers = require '../helpers/underscore-helpers'
|
||||
|
||||
|
||||
require '../utils/string'
|
||||
escapeLaTeX = require 'escape-latex'
|
||||
|
||||
###*
|
||||
Perform template-based resume generation using Underscore.js.
|
||||
@ -41,11 +41,23 @@ UnderscoreGenerator = module.exports =
|
||||
delims = _.mapObject delims, (val,key) -> new RegExp val, "ig"
|
||||
_.templateSettings = delims;
|
||||
|
||||
# Strip {# comments #}
|
||||
jst = jst.replace delims.comment, ''
|
||||
# Massage resume strings / text
|
||||
r = null
|
||||
switch format
|
||||
when 'html' then r = json.markdownify()
|
||||
when 'pdf' then r = json.markdownify()
|
||||
when 'png' then r = json.markdownify()
|
||||
when 'latex'
|
||||
traverse = require 'traverse'
|
||||
r = traverse(json).map (x) ->
|
||||
if @isLeaf && String.is @node
|
||||
return escapeLaTeX @node
|
||||
@node
|
||||
else r = json
|
||||
|
||||
# Set up the context
|
||||
ctx =
|
||||
r: if format == 'html' || format == 'pdf' || format == 'png' then json.markdownify() else json
|
||||
r: r
|
||||
filt: opts.filters
|
||||
XML: require 'xml-escape'
|
||||
RAW: json
|
||||
@ -54,5 +66,8 @@ UnderscoreGenerator = module.exports =
|
||||
headFragment: opts.headFragment || ''
|
||||
opts: opts
|
||||
|
||||
# Link to our helpers
|
||||
registerHelpers theme, opts, cssInfo, ctx, @
|
||||
|
||||
# Generate!
|
||||
@generateSimple ctx, jst
|
||||
|
Loading…
Reference in New Issue
Block a user