mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 19:06:31 +00:00
Adapt new page.parse api for tests
This commit is contained in:
@@ -29,8 +29,9 @@ Generator.prototype.convertFile = function(content, input) {
|
||||
dir: path.dirname(input) || '/'
|
||||
});
|
||||
})
|
||||
.then(function(sections) {
|
||||
json.sections = sections;
|
||||
.then(function(parsed) {
|
||||
json.lexed = parsed.lexed;
|
||||
json.sections = parsed.sections;
|
||||
})
|
||||
.then(function() {
|
||||
return fs.writeFile(
|
||||
|
||||
@@ -120,7 +120,7 @@ Generator.prototype.prepareFile = function(content, _input) {
|
||||
.then(function() {
|
||||
// Lex, parse includes and get
|
||||
// Get HTML generated sections
|
||||
return parse.page(page, {
|
||||
return parse.page(page.content, {
|
||||
// Local files path
|
||||
dir: path.dirname(_input) || '/',
|
||||
|
||||
@@ -134,8 +134,9 @@ Generator.prototype.prepareFile = function(content, _input) {
|
||||
], path.join, fs.readFileSync)
|
||||
});
|
||||
})
|
||||
.then(function(sections) {
|
||||
page.sections = sections;
|
||||
.then(function(parsed) {
|
||||
page.lexed = parsed.lexed;
|
||||
page.sections = parsed.sections;
|
||||
|
||||
// Use plugin hook
|
||||
return _callHook("page");
|
||||
|
||||
+7
-4
@@ -47,13 +47,14 @@ function quizQuestion(node) {
|
||||
}
|
||||
}
|
||||
|
||||
function parsePage(page, options) {
|
||||
function parsePage(src, options) {
|
||||
options = options || {};
|
||||
|
||||
// Lex if not already lexed
|
||||
page.lexed = (_.isArray(page.content) ? page.content : lex(include(page.content, options.includer || function() { return undefined; })))
|
||||
return page.lexed
|
||||
.map(function(section) {
|
||||
var parsed = {
|
||||
lexed: (_.isArray(src) ? page.content : lex(include(src, options.includer || function() { return undefined; })))
|
||||
};
|
||||
parsed.sections = parsed.lexed.map(function(section) {
|
||||
// Transform given type
|
||||
if(section.type === 'exercise') {
|
||||
var nonCodeNodes = _.reject(section, {
|
||||
@@ -151,6 +152,8 @@ function parsePage(page, options) {
|
||||
content: render(section, options)
|
||||
};
|
||||
});
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
// Exports
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ var FIXTURES_DIR = path.join(__dirname, './fixtures/');
|
||||
|
||||
function loadPage (name, options) {
|
||||
var CONTENT = fs.readFileSync(FIXTURES_DIR + name + '.md', 'utf8');
|
||||
return page(CONTENT, options);
|
||||
return page(CONTENT, options).sections;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ var page = require('../').parse.page;
|
||||
|
||||
function loadPage (name, options) {
|
||||
var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/' + name + '.md'), 'utf8');
|
||||
return page(CONTENT, options);
|
||||
return page(CONTENT, options).sections;
|
||||
}
|
||||
|
||||
var LEXED = loadPage('PAGE', {
|
||||
|
||||
Reference in New Issue
Block a user