diff options
-rw-r--r-- | test/books/basic/README.md | 4 | ||||
-rw-r--r-- | test/helper.js | 10 | ||||
-rw-r--r-- | test/plugins.js | 27 | ||||
-rw-r--r-- | test/plugins/highlight/index.js | 9 | ||||
-rw-r--r-- | test/plugins/highlight/package.json | 9 |
5 files changed, 58 insertions, 1 deletions
diff --git a/test/books/basic/README.md b/test/books/basic/README.md index 09ade40..73d74c0 100644 --- a/test/books/basic/README.md +++ b/test/books/basic/README.md @@ -1,3 +1,7 @@ # Readme Default description for the book. + +``` +test +``` diff --git a/test/helper.js b/test/helper.js index f6b671b..ef5c45c 100644 --- a/test/helper.js +++ b/test/helper.js @@ -17,9 +17,17 @@ var TMPDIR = os.tmpdir(); // Generate and return a book -function generateBook(bookId, test) { +function generateBook(bookId, test, options) { + options = _.defaults(options || {}, { + before: function() {} + }); + return parseBook(bookId, test) .then(function(book) { + return Q(options.before(book)) + .thenResolve(book); + }) + .then(function(book) { return book.generate(test) .thenResolve(book); }); diff --git a/test/plugins.js b/test/plugins.js index d10e0b5..a81110c 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -1,6 +1,7 @@ var _ = require('lodash'); var should = require('should'); var path = require('path'); +var fs = require('fs'); var Plugin = require('../lib/plugin'); var parsers = require("gitbook-parsers"); @@ -234,5 +235,31 @@ describe('Plugins', function () { }); }); }); + + describe('Replace code highlighting', function() { + it('should correctly replace highlighting', function() { + return books.generate('basic', 'website', { + before: function(book) { + var plugin = new Plugin(book, "blocks"); + plugin.load("./highlight", PLUGINS_ROOT); + + return book.plugins.load(plugin); + } + }) + .then(function() { + var PAGE = fs.readFileSync( + path.join(book.options.output, "index.html"), + { encoding: "utf-8" } + ); + + PAGE.should.be.html({ + "code": { + count: 1, + text: 'code__test\n__code' + } + }); + }); + }) + }); }); diff --git a/test/plugins/highlight/index.js b/test/plugins/highlight/index.js new file mode 100644 index 0000000..01202f2 --- /dev/null +++ b/test/plugins/highlight/index.js @@ -0,0 +1,9 @@ +module.exports = { + blocks: { + "code": { + process: function(blk) { + return "code_"+blk.body+"_code"; + } + } + } +};
\ No newline at end of file diff --git a/test/plugins/highlight/package.json b/test/plugins/highlight/package.json new file mode 100644 index 0000000..6b69488 --- /dev/null +++ b/test/plugins/highlight/package.json @@ -0,0 +1,9 @@ +{ + "name": "gitbook-plugin-highlight", + "description": "Highlight coe blocks", + "main": "index.js", + "version": "0.0.1", + "engines": { + "gitbook": "*" + } +}
\ No newline at end of file |