diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-14 22:41:34 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-14 22:41:34 +0100 |
commit | 2cab0187919b1c8d9cb7dcdcd04d45e1b536b4ef (patch) | |
tree | 418e94091b340e49bf4ab4eb2bd73cbb7690bd20 /lib | |
parent | bcb34dcd79f1ff49e947e16e91528ebe554c8449 (diff) | |
parent | ae52ef5b788a460e3fa42ad0d5326267daa71c3c (diff) | |
download | gitbook-2cab0187919b1c8d9cb7dcdcd04d45e1b536b4ef.zip gitbook-2cab0187919b1c8d9cb7dcdcd04d45e1b536b4ef.tar.gz gitbook-2cab0187919b1c8d9cb7dcdcd04d45e1b536b4ef.tar.bz2 |
Merge pull request #553 from GitbookIO/fix/summary-whitespace
Fix/summary whitespace
Diffstat (limited to 'lib')
-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) }; } |