diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2015-01-14 22:17:15 +0100 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2015-01-14 22:17:15 +0100 |
commit | ae52ef5b788a460e3fa42ad0d5326267daa71c3c (patch) | |
tree | 418e94091b340e49bf4ab4eb2bd73cbb7690bd20 /lib/parse/summary.js | |
parent | f88951546d59776c9be30973c782347ba125d3aa (diff) | |
download | gitbook-ae52ef5b788a460e3fa42ad0d5326267daa71c3c.zip gitbook-ae52ef5b788a460e3fa42ad0d5326267daa71c3c.tar.gz gitbook-ae52ef5b788a460e3fa42ad0d5326267daa71c3c.tar.bz2 |
Handle whitespace between lists in SUMMARY.md
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) }; } |