diff options
-rw-r--r-- | lib/parse/summary.js | 12 | ||||
-rw-r--r-- | test/fixtures/SUMMARY.md | 1 | ||||
-rw-r--r-- | test/summary.js | 1 |
3 files changed, 10 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 { diff --git a/test/fixtures/SUMMARY.md b/test/fixtures/SUMMARY.md index 74bbd1b..1145025 100644 --- a/test/fixtures/SUMMARY.md +++ b/test/fixtures/SUMMARY.md @@ -3,6 +3,7 @@ * [Chapter 1](chapter-1/README.md) * [Article 1](chapter-1/ARTICLE1.md) * [Article 2](chapter-1/ARTICLE2.md) + * [article 1.2.1](chapter-1/ARTICLE-1-2-1.md) * [Chapter 2](chapter-2/README.md) * [Chapter 3](chapter-3/README.md) * [Chapter 4](chapter-4/README.md) diff --git a/test/summary.js b/test/summary.js index 9af1f9f..0316b31 100644 --- a/test/summary.js +++ b/test/summary.js @@ -50,5 +50,6 @@ describe('Summary parsing', function () { assert.equal(c[0].articles[0].level, '1.1'); assert.equal(c[0].articles[1].level, '1.2'); + assert.equal(c[0].articles[1].articles[0].level, '1.2.1'); }); }); |