Normalize intro node in Summary parsing

This commit is contained in:
Aaron O'Mullan
2014-06-16 00:26:11 -07:00
parent a258feea37
commit 4c3dbca5ca
+22 -5
View File
@@ -94,18 +94,35 @@ function parseChapter(nodes, nums) {
});
}
function defaultChapterList(chapterList) {
var first = _.first(chapterList);
var chapter = parseChapter(first, [0]);
// Already have README node, we're good to go
if(chapter.path === 'README.md') {
return chapterList;
}
return [
[ { type: 'text', text: '[Introduction](README.md)' } ]
].concat(chapterList);
}
function parseSummary(src) {
var nodes = marked.lexer(src);
// Get out list of chapters
var chapterList = filterList(nodes);
var chapterList = listSplit(
filterList(nodes),
'list_item_start', 'list_item_end'
);
// Split out chapter sections
var chapters = _.chain(listSplit(chapterList, 'list_item_start', 'list_item_end'))
var chapters = defaultChapterList(chapterList)
.map(function(nodes, i) {
return parseChapter(nodes, [i + 1]);
})
.value();
return parseChapter(nodes, [i]);
});
return {
chapters: chapters