From 41e5ca8422357797c698180b3d0798f2b907e4cd Mon Sep 17 00:00:00 2001 From: Samy Pesse Date: Tue, 8 Sep 2015 23:55:30 +0200 Subject: [PATCH 1/2] Add test for blocks without parsing --- test/plugins.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/plugins.js b/test/plugins.js index e3d0c4979..2309395c6 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -3,6 +3,7 @@ var should = require('should'); var path = require('path'); var Plugin = require('../lib/plugin'); +var parsers = require("gitbook-parsers"); var PLUGINS_ROOT = path.resolve(__dirname, 'plugins'); describe('Plugins', function () { @@ -200,5 +201,38 @@ describe('Plugins', function () { }); }); }); + + describe('Blocks without parsing', function() { + var plugin; + + before(function() { + plugin = new Plugin(book, "blocks"); + plugin.load("./blocks", PLUGINS_ROOT); + + return book.plugins.load(plugin); + }); + + var testTpl = function(markup, str, args, options) { + var filetype = parsers.get(markup); + + return book.template.renderString(str, args, options) + .then(filetype.page).get('sections').get(0).get('content') + .then(book.template.postProcess) + }; + + it('should correctly process unparsable for markdown', function() { + return testTpl('.md', '{% test %}**hello**{% endtest %}') + .then(function(content) { + content.should.equal("

test**hello**test

\n"); + }); + }); + + it('should correctly process unparsable for asciidoc', function() { + return testTpl('.adoc', '{% test %}**hello**{% endtest %}') + .then(function(content) { + content.should.equal('
\n

test**hello**test

\n
\n'); + }); + }); + }); }); From aa44a109c6e4ec2814d49e4989d06539aa6dae53 Mon Sep 17 00:00:00 2001 From: Samy Pesse Date: Tue, 8 Sep 2015 23:57:40 +0200 Subject: [PATCH 2/2] Use position indicator that doesn't conflict with asciidoc --- lib/template.js | 10 +++++----- test/plugins.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/template.js b/lib/template.js index bc3e53e82..801440567 100644 --- a/lib/template.js +++ b/lib/template.js @@ -103,16 +103,16 @@ TemplateEngine.prototype.processBlock = function(blk) { return blk.body; } - // Return it as a macro - return "%+%"+blk.id+"%+%"; + // Return it as a position marker + return "@%@"+blk.id+"@%@"; }; -// Replace blocks by body after processing -// This is done to avoid that markdown processer parse the block content +// Replace position markers of blocks by body after processing +// This is done to avoid that markdown/asciidoc processer parse the block content TemplateEngine.prototype.replaceBlocks = function(content) { var that = this; - return content.replace(/\%\+\%([\s\S]+?)\%\+\%/g, function(match, key) { + return content.replace(/\@\%\@([\s\S]+?)\@\%\@/g, function(match, key) { var blk = that.blocks[key]; if (!blk) return match; diff --git a/test/plugins.js b/test/plugins.js index 2309395c6..d10e0b5f7 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -230,7 +230,7 @@ describe('Plugins', function () { it('should correctly process unparsable for asciidoc', function() { return testTpl('.adoc', '{% test %}**hello**{% endtest %}') .then(function(content) { - content.should.equal('
\n

test**hello**test

\n
\n'); + content.should.equal('
\n

test**hello**test

\n
'); }); }); });