From 45891d80c7f7d0f4ece53dbaf7f9f3717dc58b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Mon, 26 May 2014 17:21:23 +0200 Subject: [PATCH 1/5] Parse more than two level in summary --- lib/parse/summary.js | 12 ++++++++---- test/fixtures/SUMMARY.md | 1 + test/summary.js | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/parse/summary.js b/lib/parse/summary.js index af13088e2..f7dcdc9b4 100644 --- a/lib/parse/summary.js +++ b/lib/parse/summary.js @@ -90,9 +90,11 @@ function parseArticle(chapterNum, nodes, idx) { return parseTitle(_.first(nodes).text, [chapterNum, idx+1]); } -function parseChapter(nodes, idx) { - return _.extend(parseTitle(_.first(nodes).text, [idx+1]), { - articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), parseArticle.bind(null, idx+1)) +function parseChapter(nodes, nums) { + return _.extend(parseTitle(_.first(nodes).text, nums), { + articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), function(nodes, i) { + return parseChapter(nodes, nums.concat(i + 1)); + }) }); } @@ -104,7 +106,9 @@ function parseSummary(src) { // Split out chapter sections var chapters = _.chain(listSplit(chapterList, 'list_item_start', 'list_item_end')) - .map(parseChapter) + .map(function(nodes, i) { + return parseChapter(nodes, [i + 1]); + }) .value(); return { diff --git a/test/fixtures/SUMMARY.md b/test/fixtures/SUMMARY.md index 74bbd1b8b..114502506 100644 --- a/test/fixtures/SUMMARY.md +++ b/test/fixtures/SUMMARY.md @@ -3,6 +3,7 @@ * [Chapter 1](chapter-1/README.md) * [Article 1](chapter-1/ARTICLE1.md) * [Article 2](chapter-1/ARTICLE2.md) + * [article 1.2.1](chapter-1/ARTICLE-1-2-1.md) * [Chapter 2](chapter-2/README.md) * [Chapter 3](chapter-3/README.md) * [Chapter 4](chapter-4/README.md) diff --git a/test/summary.js b/test/summary.js index 9af1f9f96..0316b31bd 100644 --- a/test/summary.js +++ b/test/summary.js @@ -50,5 +50,6 @@ describe('Summary parsing', function () { assert.equal(c[0].articles[0].level, '1.1'); assert.equal(c[0].articles[1].level, '1.2'); + assert.equal(c[0].articles[1].articles[0].level, '1.2.1'); }); }); From f228f646ebea7209bfa8b418853948ef62f92b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Mon, 26 May 2014 17:23:19 +0200 Subject: [PATCH 2/5] Remove useless method parseArticle --- lib/parse/summary.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/parse/summary.js b/lib/parse/summary.js index f7dcdc9b4..1fd5676ed 100644 --- a/lib/parse/summary.js +++ b/lib/parse/summary.js @@ -86,10 +86,6 @@ function parseTitle(src, nums) { }; } -function parseArticle(chapterNum, nodes, idx) { - return parseTitle(_.first(nodes).text, [chapterNum, idx+1]); -} - function parseChapter(nodes, nums) { return _.extend(parseTitle(_.first(nodes).text, nums), { articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), function(nodes, i) { From 8b7abbd6f489c71f9c3b657d2a989b00fcdb09b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Mon, 26 May 2014 17:31:35 +0200 Subject: [PATCH 3/5] Render articles of level > 2 in summary --- theme/templates/includes/book/summary.html | 46 ++++++++++------------ 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/theme/templates/includes/book/summary.html b/theme/templates/includes/book/summary.html index b4859fce0..697cce87c 100644 --- a/theme/templates/includes/book/summary.html +++ b/theme/templates/includes/book/summary.html @@ -1,3 +1,22 @@ +{% macro articles(_articles) %} + {% for item in _articles %} +
  • + {% if item.path %} + + {{ item.level }}. {{ item.title }} + + {% else %} + {{ item.level }}. {{ item.title }} + {% endif %} + {% if item.articles.length > 0 %} +
      + {{ articles(item.articles) }} +
    + {% endif %} +
  • + {% endfor %} +{% endmacro %} +