From 4c3dbca5ca12c2ea3806a17dc186deff5ce83b79 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Mon, 16 Jun 2014 00:26:11 -0700 Subject: [PATCH] Normalize intro node in Summary parsing --- lib/parse/summary.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/parse/summary.js b/lib/parse/summary.js index 1fd5676ed..7e54df0bb 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