diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/parse/summary.js | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/parse/summary.js b/lib/parse/summary.js index 1fd5676..7e54df0 100644 --- a/lib/parse/summary.js +++ b/lib/parse/summary.js @@ -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 |