diff options
Diffstat (limited to 'lib/parse/summary.js')
-rw-r--r-- | lib/parse/summary.js | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/parse/summary.js b/lib/parse/summary.js index 21eadd1..2fdec8a 100644 --- a/lib/parse/summary.js +++ b/lib/parse/summary.js @@ -60,6 +60,26 @@ function filterList(nodes) { .value().slice(1, -1); } +function skipSpace(nodes) { + return _.filter(nodes, function(node) { + return node && node.type != 'space'; + }); +} + +function correctLoose(nodes) { + return _.map(nodes, function(node) { + // Return normal nodes + if(!node || node.type != 'loose_item_start') { + return node + } + + // Correct loose items + node.type = 'list_item_start'; + + return node; + }) +} + // Parses an Article or Chapter title // supports extracting links function parseTitle(src, nums) { @@ -123,18 +143,17 @@ function listGroups(src) { // Get out groups of lists return listSplit( - filterList(nodes), + filterList(correctLoose(skipSpace(nodes))), 'list_item_start', 'list_item_end' ); } function parseSummary(src) { // Split out chapter sections - var chapters = defaultChapterList(listGroups(src)) - .map(parseChapter); + var chapters = defaultChapterList(listGroups(src)); return { - chapters: chapters + chapters: chapters.map(parseChapter) }; } |