mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Use external gitbook parsers
This commit is contained in:
+3
-3
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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"));
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
@@ -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
|
||||
};
|
||||
+1
-2
@@ -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",
|
||||
|
||||
+1
-1
@@ -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");
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user