summaryrefslogtreecommitdiffstats
path: root/lib/parse
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-05-26 17:21:23 +0200
committerSamy Pessé <samypesse@gmail.com>2014-05-26 17:21:23 +0200
commit45891d80c7f7d0f4ece53dbaf7f9f3717dc58b6f (patch)
treea32181a5bd2b69873f42814c6063d58f35b37e11 /lib/parse
parentac900aa37f7b2ea584efb992fe6bcdb69e8b01d6 (diff)
downloadgitbook-45891d80c7f7d0f4ece53dbaf7f9f3717dc58b6f.zip
gitbook-45891d80c7f7d0f4ece53dbaf7f9f3717dc58b6f.tar.gz
gitbook-45891d80c7f7d0f4ece53dbaf7f9f3717dc58b6f.tar.bz2
Parse more than two level in summary
Diffstat (limited to 'lib/parse')
-rw-r--r--lib/parse/summary.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/parse/summary.js b/lib/parse/summary.js
index af13088..f7dcdc9 100644
--- a/lib/parse/summary.js
+++ b/lib/parse/summary.js
@@ -90,9 +90,11 @@ function parseArticle(chapterNum, nodes, idx) {
return parseTitle(_.first(nodes).text, [chapterNum, idx+1]);
}
-function parseChapter(nodes, idx) {
- return _.extend(parseTitle(_.first(nodes).text, [idx+1]), {
- articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), parseArticle.bind(null, idx+1))
+function parseChapter(nodes, 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));
+ })
});
}
@@ -104,7 +106,9 @@ function parseSummary(src) {
// Split out chapter sections
var chapters = _.chain(listSplit(chapterList, 'list_item_start', 'list_item_end'))
- .map(parseChapter)
+ .map(function(nodes, i) {
+ return parseChapter(nodes, [i + 1]);
+ })
.value();
return {