diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-27 22:34:48 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-27 22:34:48 +0100 |
commit | d1b295099320eeb66c615737ee73c746eb7bb0dc (patch) | |
tree | ad2da6b1f0a71689448cd8c8b2961da3d327d224 /lib/template.js | |
parent | d8995200e6802f77de1f0e3699e208695c89b95e (diff) | |
download | gitbook-d1b295099320eeb66c615737ee73c746eb7bb0dc.zip gitbook-d1b295099320eeb66c615737ee73c746eb7bb0dc.tar.gz gitbook-d1b295099320eeb66c615737ee73c746eb7bb0dc.tar.bz2 |
Check parser used before applying template shortcuts
Diffstat (limited to 'lib/template.js')
-rw-r--r-- | lib/template.js | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/template.js b/lib/template.js index 070173c..a34f79b 100644 --- a/lib/template.js +++ b/lib/template.js @@ -203,8 +203,9 @@ TemplateEngine.prototype.addBlock = function(name, block) { // Add shortcuts if (!_.isArray(block.shortcuts)) block.shortcuts = [block.shortcuts]; _.each(block.shortcuts, function(shortcut) { - this.log.debug.ln("add template shortcut from '"+shortcut.start+"' to block '"+name+"'"); + this.log.debug.ln("add template shortcut from '"+shortcut.start+"' to block '"+name+"' for parsers ", shortcut.parsers); this.shortcuts.push({ + parsers: shortcut.parsers, start: shortcut.start, end: shortcut.end, tag: { @@ -216,7 +217,8 @@ TemplateEngine.prototype.addBlock = function(name, block) { }; // Apply a shortcut to a string -TemplateEngine.prototype._applyShortcut = function(content, shortcut) { +TemplateEngine.prototype._applyShortcut = function(parser, content, shortcut) { + if (!_.contains(shortcut.parsers, parser)) return content; var regex = new RegExp( stringUtils.escapeRegex(shortcut.start) + "\\s*([\\s\\S]*?[^\\$])\\s*" + stringUtils.escapeRegex(shortcut.end), 'g' @@ -237,11 +239,14 @@ TemplateEngine.prototype.renderString = function(content, context, options) { version: pkg.version } }); - options = _.defaults(options || {}, { path: null}); + options = _.defaults(options || {}, { + path: null, + type: null + }); if (options.path) options.path = this.book.resolve(options.path); // Replace shortcuts - content = _.reduce(this.shortcuts, this._applyShortcut.bind(this), content); + content = _.reduce(this.shortcuts, _.partial(this._applyShortcut.bind(this), options.type), content); return Q.nfcall(this.env.renderString.bind(this.env), content, context, options); }; @@ -273,7 +278,8 @@ TemplateEngine.prototype.renderPage = function(page) { }; return that.renderString(page.content, context, { - path: page.path + path: page.path, + type: page.type }); }); }; |