diff options
-rw-r--r-- | lib/generate/json/index.js | 5 | ||||
-rw-r--r-- | lib/generate/site/index.js | 7 | ||||
-rw-r--r-- | lib/parse/page.js | 11 | ||||
-rw-r--r-- | test/includes.js | 2 | ||||
-rw-r--r-- | test/page.js | 2 |
5 files changed, 16 insertions, 11 deletions
diff --git a/lib/generate/json/index.js b/lib/generate/json/index.js index 6bc5211..a252ed3 100644 --- a/lib/generate/json/index.js +++ b/lib/generate/json/index.js @@ -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( diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index 47d09f2..f0a4780 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -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"); diff --git a/lib/parse/page.js b/lib/parse/page.js index 2cbbbf4..ca7441f 100644 --- a/lib/parse/page.js +++ b/lib/parse/page.js @@ -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 diff --git a/test/includes.js b/test/includes.js index 09f76d3..6954d3f 100644 --- a/test/includes.js +++ b/test/includes.js @@ -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; } diff --git a/test/page.js b/test/page.js index cd843c6..0633117 100644 --- a/test/page.js +++ b/test/page.js @@ -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', { |