Fix LANGS.md parsing

And cleanup Summary parsing
This commit is contained in:
Aaron O'Mullan
2014-06-17 16:18:08 -07:00
parent 3aefcaea73
commit 6c5c8e6eb7
2 changed files with 23 additions and 13 deletions
+8 -6
View File
@@ -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
View File
@@ -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;