diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-06-17 16:18:08 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-06-17 16:18:08 -0700 |
commit | 6c5c8e6eb71889977df189223be70d8ae623bf30 (patch) | |
tree | fbb009b17d365507c93fdb71684f4a93bb8bd3cd /lib/parse | |
parent | 3aefcaea73c481081908653b6256c9efd71d64a3 (diff) | |
download | gitbook-6c5c8e6eb71889977df189223be70d8ae623bf30.zip gitbook-6c5c8e6eb71889977df189223be70d8ae623bf30.tar.gz gitbook-6c5c8e6eb71889977df189223be70d8ae623bf30.tar.bz2 |
Fix LANGS.md parsing
And cleanup Summary parsing
Diffstat (limited to 'lib/parse')
-rw-r--r-- | lib/parse/langs.js | 14 | ||||
-rw-r--r-- | lib/parse/summary.js | 22 |
2 files changed, 23 insertions, 13 deletions
diff --git a/lib/parse/langs.js b/lib/parse/langs.js index 46c3a46..01b7c8c 100644 --- a/lib/parse/langs.js +++ b/lib/parse/langs.js @@ -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;
\ No newline at end of file diff --git a/lib/parse/summary.js b/lib/parse/summary.js index 7e54df0..7746f10 100644 --- a/lib/parse/summary.js +++ b/lib/parse/summary.js @@ -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; |