summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-09-09 00:01:43 +0200
committerSamy Pessé <samypesse@gmail.com>2015-09-09 00:01:43 +0200
commit471c124a988adeeafead67d8ae12bb9433e8e5b4 (patch)
tree899dcf536f7641d2ef2267b17cd1736fa4c86e6a
parent53af8b2bb661e5aebb6732bee24464e2b1068994 (diff)
parentaa44a109c6e4ec2814d49e4989d06539aa6dae53 (diff)
downloadgitbook-471c124a988adeeafead67d8ae12bb9433e8e5b4.zip
gitbook-471c124a988adeeafead67d8ae12bb9433e8e5b4.tar.gz
gitbook-471c124a988adeeafead67d8ae12bb9433e8e5b4.tar.bz2
Merge pull request #908 from GitbookIO/fix/asciidoc_blocks
Fix blocks in asciidoc
-rw-r--r--lib/template.js10
-rw-r--r--test/plugins.js34
2 files changed, 39 insertions, 5 deletions
diff --git a/lib/template.js b/lib/template.js
index bc3e53e..8014405 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 e3d0c49..d10e0b5 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("<p>test**hello**test</p>\n");
+ });
+ });
+
+ it('should correctly process unparsable for asciidoc', function() {
+ return testTpl('.adoc', '{% test %}**hello**{% endtest %}')
+ .then(function(content) {
+ content.should.equal('<div class="paragraph">\n<p>test**hello**test</p>\n</div>');
+ });
+ });
+ });
});