Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45891d8

Browse files
committed
Parse more than two level in summary
1 parent ac900aa commit 45891d8

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

lib/parse/summary.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ function parseArticle(chapterNum, nodes, idx) {
9090
return parseTitle(_.first(nodes).text, [chapterNum, idx+1]);
9191
}
9292

93-
function parseChapter(nodes, idx) {
94-
return _.extend(parseTitle(_.first(nodes).text, [idx+1]), {
95-
articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), parseArticle.bind(null, idx+1))
93+
function parseChapter(nodes, nums) {
94+
return _.extend(parseTitle(_.first(nodes).text, nums), {
95+
articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), function(nodes, i) {
96+
return parseChapter(nodes, nums.concat(i + 1));
97+
})
9698
});
9799
}
98100

@@ -104,7 +106,9 @@ function parseSummary(src) {
104106

105107
// Split out chapter sections
106108
var chapters = _.chain(listSplit(chapterList, 'list_item_start', 'list_item_end'))
107-
.map(parseChapter)
109+
.map(function(nodes, i) {
110+
return parseChapter(nodes, [i + 1]);
111+
})
108112
.value();
109113

110114
return {

test/fixtures/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* [Chapter 1](chapter-1/README.md)
44
* [Article 1](chapter-1/ARTICLE1.md)
55
* [Article 2](chapter-1/ARTICLE2.md)
6+
* [article 1.2.1](chapter-1/ARTICLE-1-2-1.md)
67
* [Chapter 2](chapter-2/README.md)
78
* [Chapter 3](chapter-3/README.md)
89
* [Chapter 4](chapter-4/README.md)

test/summary.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ describe('Summary parsing', function () {
5050

5151
assert.equal(c[0].articles[0].level, '1.1');
5252
assert.equal(c[0].articles[1].level, '1.2');
53+
assert.equal(c[0].articles[1].articles[0].level, '1.2.1');
5354
});
5455
});

0 commit comments

Comments
 (0)