Skip to content

Commit

Permalink
Handle whitespace between lists in SUMMARY.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron O'Mullan committed Jan 14, 2015
1 parent f889515 commit ae52ef5
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions lib/parse/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
};
}

Expand Down

0 comments on commit ae52ef5

Please sign in to comment.