mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Normalize intro node in Summary parsing
This commit is contained in:
+22
-5
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user