mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 11:26:31 +00:00
Fix LANGS.md parsing
And cleanup Summary parsing
This commit is contained in:
+8
-6
@@ -1,13 +1,14 @@
|
||||
var _ = require("lodash")
|
||||
var parseSummary = require("./summary");
|
||||
var _ = require("lodash");
|
||||
var parseEntries = require("./summary").entries;
|
||||
|
||||
|
||||
var parseLangs = function(content) {
|
||||
var summary = parseSummary(content);
|
||||
var entries = parseEntries(content);
|
||||
|
||||
return {
|
||||
list: _.chain(summary.chapters)
|
||||
list: _.chain(entries)
|
||||
.filter(function(entry) {
|
||||
return entry.path != null;
|
||||
return Boolean(entry.path);
|
||||
})
|
||||
.map(function(entry) {
|
||||
return {
|
||||
@@ -17,7 +18,8 @@ var parseLangs = function(content) {
|
||||
};
|
||||
})
|
||||
.value()
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
module.exports = parseLangs;
|
||||
+15
-7
@@ -87,6 +87,9 @@ function parseTitle(src, nums) {
|
||||
}
|
||||
|
||||
function parseChapter(nodes, nums) {
|
||||
// Convert single number to an array
|
||||
nums = _.isArray(nums) ? nums : [nums];
|
||||
|
||||
return _.extend(parseTitle(_.first(nodes).text, nums), {
|
||||
articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), function(nodes, i) {
|
||||
return parseChapter(nodes, nums.concat(i + 1));
|
||||
@@ -109,26 +112,31 @@ function defaultChapterList(chapterList) {
|
||||
].concat(chapterList);
|
||||
}
|
||||
|
||||
function parseSummary(src) {
|
||||
function listGroups(src) {
|
||||
var nodes = marked.lexer(src);
|
||||
|
||||
// Get out list of chapters
|
||||
var chapterList = listSplit(
|
||||
// Get out groups of lists
|
||||
return listSplit(
|
||||
filterList(nodes),
|
||||
'list_item_start', 'list_item_end'
|
||||
);
|
||||
}
|
||||
|
||||
function parseSummary(src) {
|
||||
// Split out chapter sections
|
||||
var chapters = defaultChapterList(chapterList)
|
||||
.map(function(nodes, i) {
|
||||
return parseChapter(nodes, [i]);
|
||||
});
|
||||
var chapters = defaultChapterList(listGroups(src))
|
||||
.map(parseChapter);
|
||||
|
||||
return {
|
||||
chapters: chapters
|
||||
};
|
||||
}
|
||||
|
||||
function parseEntries (src) {
|
||||
return listGroups(src).map(parseChapter);
|
||||
}
|
||||
|
||||
|
||||
// Exports
|
||||
module.exports = parseSummary;
|
||||
module.exports.entries = parseEntries;
|
||||
|
||||
Reference in New Issue
Block a user