diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-09-14 18:26:26 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-09-14 18:26:26 +0200 |
commit | afd5465a6129e96bce62dab26a4ee41e7af7365c (patch) | |
tree | 6e500ed55e65a6f6e5991913f11850d17c8ed721 /test | |
parent | 3bf592f870eb24d1b4753fa538bad2cbfaa98a24 (diff) | |
parent | fe604733debe42a287f3c44705e16d9d0ec85908 (diff) | |
download | gitbook-afd5465a6129e96bce62dab26a4ee41e7af7365c.zip gitbook-afd5465a6129e96bce62dab26a4ee41e7af7365c.tar.gz gitbook-afd5465a6129e96bce62dab26a4ee41e7af7365c.tar.bz2 |
Merge pull request #928 from GitbookIO/feature/highlight_block
Code highlighting extended by plugins
Diffstat (limited to 'test')
-rw-r--r-- | test/assertions.js | 13 | ||||
-rw-r--r-- | test/books/highlight/README.md | 15 | ||||
-rw-r--r-- | test/books/highlight/SUMMARY.md | 1 | ||||
-rw-r--r-- | test/codehighlighting.js | 58 | ||||
-rw-r--r-- | test/helper.js | 12 | ||||
-rw-r--r-- | test/plugins.js | 1 | ||||
-rw-r--r-- | test/plugins/replace_highlight/index.js | 11 | ||||
-rw-r--r-- | test/plugins/replace_highlight/package.json | 9 |
8 files changed, 118 insertions, 2 deletions
diff --git a/test/assertions.js b/test/assertions.js index 7a34380..f81645b 100644 --- a/test/assertions.js +++ b/test/assertions.js @@ -26,14 +26,27 @@ should.Assertion.add('html', function(rules, description) { _.each(rules, function(validations, query) { validations = _.defaults(validations || {}, { + // Select a specific element in the list of matched elements + index: null, + + // Check that there is the correct count of elements count: 1, + + // Check attribute values attributes: {}, + + // Trim inner text trim: false, + + // Check inner text text: undefined }); var $el = $(query); + // Select correct element + if (_.isNumber(validations.index)) $el = $($el.get(validations.index)); + // Test number of elements $el.length.should.be.equal(validations.count); diff --git a/test/books/highlight/README.md b/test/books/highlight/README.md new file mode 100644 index 0000000..417fabc --- /dev/null +++ b/test/books/highlight/README.md @@ -0,0 +1,15 @@ +# Readme + +Block without language + +``` +test 1 +``` + +Block with a language + +```lang +test 2 +``` + +Inline code: `test 3`
\ No newline at end of file diff --git a/test/books/highlight/SUMMARY.md b/test/books/highlight/SUMMARY.md new file mode 100644 index 0000000..ac9323c --- /dev/null +++ b/test/books/highlight/SUMMARY.md @@ -0,0 +1 @@ +# Summary diff --git a/test/codehighlighting.js b/test/codehighlighting.js new file mode 100644 index 0000000..e35f37e --- /dev/null +++ b/test/codehighlighting.js @@ -0,0 +1,58 @@ +var _ = require('lodash'); +var should = require('should'); +var path = require('path'); +var fs = require('fs'); + +var Plugin = require('../lib/plugin'); +var PLUGINS_ROOT = path.resolve(__dirname, 'plugins'); + +describe('Code Highlighting', function () { + var book, PAGE; + + before(function() { + return books.generate('highlight', 'website', { + prepare: function(_book) { + book = _book; + + var plugin = new Plugin(book, "replace_highlight"); + plugin.load("./replace_highlight", PLUGINS_ROOT); + + book.plugins.load(plugin); + } + }) + .then(function() { + PAGE = fs.readFileSync( + path.join(book.options.output, "index.html"), + { encoding: "utf-8" } + ); + }); + }); + + it('should correctly replace highlighting', function() { + PAGE.should.be.html({ + "code": { + index: 0, + text: 'code_test 1\n_code' + } + }); + }); + + it('should correctly replace highlighting with language', function() { + PAGE.should.be.html({ + "code": { + index: 1, + text: 'lang_test 2\n_lang' + } + }); + }); + + it('should correctly replace highlighting for inline code', function() { + PAGE.should.be.html({ + "code": { + index: 2, + text: 'code_test 3_code' + } + }); + }); +}); + diff --git a/test/helper.js b/test/helper.js index f6b671b..f4432a9 100644 --- a/test/helper.js +++ b/test/helper.js @@ -17,10 +17,18 @@ var TMPDIR = os.tmpdir(); // Generate and return a book -function generateBook(bookId, test) { +function generateBook(bookId, test, opts) { + opts = _.defaults(opts || {}, { + prepare: function() {} + }); + return parseBook(bookId, test) .then(function(book) { - return book.generate(test) + + return Q(opts.prepare(book)) + .then(function() { + return book.generate(test); + }) .thenResolve(book); }); } diff --git a/test/plugins.js b/test/plugins.js index d10e0b5..cc9c8e6 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"); diff --git a/test/plugins/replace_highlight/index.js b/test/plugins/replace_highlight/index.js new file mode 100644 index 0000000..25f9642 --- /dev/null +++ b/test/plugins/replace_highlight/index.js @@ -0,0 +1,11 @@ +module.exports = { + blocks: { + "code": { + process: function(blk) { + var lang = blk.kwargs.language || 'code'; + + return lang+"_"+blk.body+"_"+lang; + } + } + } +};
\ No newline at end of file diff --git a/test/plugins/replace_highlight/package.json b/test/plugins/replace_highlight/package.json new file mode 100644 index 0000000..72d1033 --- /dev/null +++ b/test/plugins/replace_highlight/package.json @@ -0,0 +1,9 @@ +{ + "name": "gitbook-plugin-replace_highlight", + "description": "Test replacing default code highlighter", + "main": "index.js", + "version": "0.0.1", + "engines": { + "gitbook": "*" + } +}
\ No newline at end of file |