Skip to content

Commit 4c3dbca

Browse files
author
Aaron O'Mullan
committed
Normalize intro node in Summary parsing
1 parent a258fee commit 4c3dbca

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

lib/parse/summary.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,35 @@ function parseChapter(nodes, nums) {
9494
});
9595
}
9696

97+
function defaultChapterList(chapterList) {
98+
var first = _.first(chapterList);
99+
100+
var chapter = parseChapter(first, [0]);
101+
102+
// Already have README node, we're good to go
103+
if(chapter.path === 'README.md') {
104+
return chapterList;
105+
}
106+
107+
return [
108+
[ { type: 'text', text: '[Introduction](README.md)' } ]
109+
].concat(chapterList);
110+
}
111+
97112
function parseSummary(src) {
98113
var nodes = marked.lexer(src);
99114

100115
// Get out list of chapters
101-
var chapterList = filterList(nodes);
116+
var chapterList = listSplit(
117+
filterList(nodes),
118+
'list_item_start', 'list_item_end'
119+
);
102120

103121
// Split out chapter sections
104-
var chapters = _.chain(listSplit(chapterList, 'list_item_start', 'list_item_end'))
122+
var chapters = defaultChapterList(chapterList)
105123
.map(function(nodes, i) {
106-
return parseChapter(nodes, [i + 1]);
107-
})
108-
.value();
124+
return parseChapter(nodes, [i]);
125+
});
109126

110127
return {
111128
chapters: chapters

0 commit comments

Comments
 (0)