diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-22 18:21:30 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-22 18:21:30 +0100 |
commit | 0ba36c6f4ed316cc157c701abe4728d64da231b4 (patch) | |
tree | be6a43d28d1411fe60cac8405dde33b2b38e6a52 | |
parent | c47093e82a1814dd421c37fc3cbef9512541d526 (diff) | |
download | gitbook-0ba36c6f4ed316cc157c701abe4728d64da231b4.zip gitbook-0ba36c6f4ed316cc157c701abe4728d64da231b4.tar.gz gitbook-0ba36c6f4ed316cc157c701abe4728d64da231b4.tar.bz2 |
Use external gitbook parsers
-rw-r--r-- | lib/book.js | 6 | ||||
-rw-r--r-- | lib/generators/site.js | 8 | ||||
-rw-r--r-- | lib/parsers.js | 34 | ||||
-rw-r--r-- | lib/utils/summary.js | 24 | ||||
-rw-r--r-- | package.json | 3 | ||||
-rw-r--r-- | test/parsing.js | 2 | ||||
-rw-r--r-- | test/website.js | 1 |
7 files changed, 14 insertions, 64 deletions
diff --git a/lib/book.js b/lib/book.js index 343a340..639adef 100644 --- a/lib/book.js +++ b/lib/book.js @@ -2,17 +2,17 @@ var Q = require("q"); var _ = require("lodash"); var path = require("path"); +var parsers = require("gitbook-parsers"); + var fs = require("./utils/fs"); var parseNavigation = require("./utils/navigation"); var parseProgress = require("./utils/progress"); var pageUtil = require("./utils/page"); -var summaryUtil = require("./utils/summary"); var Configuration = require("./configuration"); var TemplateEngine = require("./template"); var Plugin = require("./plugin"); -var parsers = require("./parsers"); var generators = require("./generators"); var Book = function(root, options, parent) { @@ -271,7 +271,7 @@ Book.prototype.parseSummary = function() { }); }) .then(function(summary) { - that.summary = summaryUtil.normalize(summary); + that.summary = summary; that.navigation = parseNavigation(that.summary, that.files); }); }; diff --git a/lib/generators/site.js b/lib/generators/site.js index 375fd5c..d5a0c08 100644 --- a/lib/generators/site.js +++ b/lib/generators/site.js @@ -130,7 +130,15 @@ Generator.prototype.writeParsedFile = function(page) { // Write the index for langs Generator.prototype.langsIndex = function(langs) { + var that = this; + var basePath = "."; + + return this._writeTemplate(this.langsTemplate, { + langs: langs, + basePath: basePath, + staticBase: path.join(basePath, "gitbook"), + }, path.join(this.options.output, "index.html")); }; diff --git a/lib/parsers.js b/lib/parsers.js deleted file mode 100644 index 523cb87..0000000 --- a/lib/parsers.js +++ /dev/null @@ -1,34 +0,0 @@ -var _ = require("lodash"); -var path = require("path"); - -// This list is ordered by priority of parsers to use -var PARSER = [ - { - name: "markdown", - extensions: [".md", ".markdown"], - parser: require("gitbook-markdown") - }, - { - name: "asciidoc", - extensions: [".adoc", ".asciidoc"], - parser: require("gitbook-asciidoc") - } -]; - -// Return a specific parser according to an extension -function getParser(ext) { - return _.find(PARSER, function(input) { - return _.contains(input.extensions, ext); - }); -} - -// Return parser for a file -function getParserForFile(filename) { - return getParser(path.extname(filename)); -}; - -module.exports = { - extensions: _.flatten(_.pluck(PARSER, "extensions")), - get: getParser, - getForFile: getParserForFile -}; diff --git a/lib/utils/summary.js b/lib/utils/summary.js deleted file mode 100644 index 274cab3..0000000 --- a/lib/utils/summary.js +++ /dev/null @@ -1,24 +0,0 @@ -var _ = require("lodash"); -var links = require("./links"); - -function normalizeChapters(chapterList, level, base) { - var i = base || 0; - return _.map(chapterList, function(chapter) { - chapter.level = (level? [level || "", i] : [i]).join("."); - chapter.exteral = links.isExternal(chapter.path); - chapter.article = normalizeChapters(chapter.articles || [], chapter.level, 1); - - i = i + 1; - return chapter; - }); -}; - -function normalizeSummary(summary) { - if (_.isArray(summary)) summary = { chapters: summary }; - summary.chapters = normalizeChapters(summary.chapters); - return summary; -}; - -module.exports = { - normalize: normalizeSummary -}; diff --git a/package.json b/package.json index 915db82..e26aa4b 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,7 @@ "resolve": "0.6.3", "fs-extra": "0.14.0", "fstream-ignore": "1.0.2", - "gitbook-markdown": "1.0.0", - "gitbook-asciidoctor": "1.0.0", + "gitbook-parsers": "1.0.0", "nunjucks": "git+https://github.com/SamyPesse/nunjucks.git#4019d1b7379372336b86ce1b0bf84352a2029747", "nunjucks-autoescape": "0.1.0", "nunjucks-filter": "0.1.0", diff --git a/test/parsing.js b/test/parsing.js index f61a4fe..ef87a91 100644 --- a/test/parsing.js +++ b/test/parsing.js @@ -28,7 +28,7 @@ describe('Book parsing', function () { assert.equal(LEXED[0].name, "Test"); assert.equal(LEXED[0].description, "a test text"); - assert.equal(LEXED[1].id, "test 2"); + assert.equal(LEXED[1].id, "test_2"); assert.equal(LEXED[1].name, "Test 2"); assert.equal(LEXED[1].description, "a second test"); }); diff --git a/test/website.js b/test/website.js index f1dabfb..54dfc8a 100644 --- a/test/website.js +++ b/test/website.js @@ -25,6 +25,7 @@ describe('Website Generator', function () { it('should correctly generate a multilingual book to website', function(done) { testGeneration(books[2], "site", function(output) { assert(fs.existsSync(path.join(output, "index.html"))); + assert(fs.existsSync(path.join(output, "gitbook"))); assert(fs.existsSync(path.join(output, "fr/index.html"))); assert(fs.existsSync(path.join(output, "en/index.html"))); }, done); |