mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-22 18:43:29 +00:00
Add base test for extending code highlighting
This commit is contained in:
@@ -339,7 +339,6 @@ TemplateEngine.prototype.addBlock = function(name, block) {
|
||||
|
||||
// Add multiple blocks
|
||||
TemplateEngine.prototype.addBlocks = function(blocks) {
|
||||
console.log('add blocks', blocks);
|
||||
_.each(blocks, function(block, name) {
|
||||
this.addBlock(name, block);
|
||||
}, this);
|
||||
@@ -351,7 +350,6 @@ TemplateEngine.prototype.applyBlock = function(name, blk) {
|
||||
var func, block, func, r;
|
||||
|
||||
block = this.blocks[name];
|
||||
console.log('applyBlock', name, block);
|
||||
if (!block) throw new Error('Block not found "'+name+'"');
|
||||
if (_.isString(blk)) {
|
||||
blk = {
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
"fs-extra": "0.16.5",
|
||||
"fstream-ignore": "1.0.2",
|
||||
"gitbook-parsers": "0.8.2",
|
||||
"nunjucks": "mozilla/nunjucks#146a63571f1910d57cc391dfe64f3789ba1f1fd1",
|
||||
"nunjucks": "mozilla/nunjucks#dc89bf91611a2101731c2c06afcf5c32160b4dc9",
|
||||
"nunjucks-autoescape": "1.0.0",
|
||||
"nunjucks-filter": "1.0.0",
|
||||
"i18n": "0.5.0",
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
# Readme
|
||||
|
||||
Default description for the book.
|
||||
|
||||
```
|
||||
test
|
||||
```
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# Readme
|
||||
|
||||
Default description for the book.
|
||||
|
||||
```
|
||||
test
|
||||
```
|
||||
@@ -0,0 +1 @@
|
||||
# Summary
|
||||
@@ -0,0 +1,34 @@
|
||||
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 () {
|
||||
it('should correctly replace highlighting', function() {
|
||||
return books.generate('highlight', 'website', {
|
||||
prepare: function(book) {
|
||||
var plugin = new Plugin(book, "highlight");
|
||||
plugin.load("./highlight", PLUGINS_ROOT);
|
||||
|
||||
book.plugins.load(plugin);
|
||||
}
|
||||
})
|
||||
.then(function(book) {
|
||||
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'
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+8
-8
@@ -17,18 +17,18 @@ var TMPDIR = os.tmpdir();
|
||||
|
||||
|
||||
// Generate and return a book
|
||||
function generateBook(bookId, test, options) {
|
||||
options = _.defaults(options || {}, {
|
||||
before: function() {}
|
||||
function generateBook(bookId, test, opts) {
|
||||
opts = _.defaults(opts || {}, {
|
||||
prepare: function() {}
|
||||
});
|
||||
|
||||
return parseBook(bookId, test)
|
||||
.then(function(book) {
|
||||
return Q(options.before(book))
|
||||
.thenResolve(book);
|
||||
})
|
||||
.then(function(book) {
|
||||
return book.generate(test)
|
||||
|
||||
return Q(opts.prepare(book))
|
||||
.then(function() {
|
||||
return book.generate(test);
|
||||
})
|
||||
.thenResolve(book);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -235,31 +235,5 @@ 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'
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user