summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-20 16:56:07 +0100
committerSamy Pessé <samypesse@gmail.com>2016-12-22 12:32:15 +0100
commit5b88703e83965f54edaf0f56f5f00d41fab33853 (patch)
treeb7c41a20669240cf10102ee75fd238635bb433b2
parentd282447802394051a1208371ddc99e9bdb841619 (diff)
downloadgitbook-5b88703e83965f54edaf0f56f5f00d41fab33853.zip
gitbook-5b88703e83965f54edaf0f56f5f00d41fab33853.tar.gz
gitbook-5b88703e83965f54edaf0f56f5f00d41fab33853.tar.bz2
Parse title for parts
-rwxr-xr-xpackages/gitbook-html/lib/summary.js6
-rw-r--r--packages/gitbook-html/lib/totext.js2
-rwxr-xr-xpackages/gitbook-html/test/fixtures/SUMMARY.html2
-rwxr-xr-xpackages/gitbook-html/test/summary.js16
4 files changed, 22 insertions, 4 deletions
diff --git a/packages/gitbook-html/lib/summary.js b/packages/gitbook-html/lib/summary.js
index 9b6b688..132dfdd 100755
--- a/packages/gitbook-html/lib/summary.js
+++ b/packages/gitbook-html/lib/summary.js
@@ -1,7 +1,7 @@
var _ = require('lodash');
var dom = require('./dom');
-var SELECTOR_LIST = '.olist > ol, ol, ul';
+var SELECTOR_LIST = 'ol, ul';
var SELECTOR_LINK = '> a, p > a';
var BL = '\n';
@@ -54,9 +54,11 @@ function parseSummary(html) {
$lists.each(function() {
var $list = $(this);
+ var $title = $list.prevUntil(SELECTOR_LIST, 'h2, h3, h4').first();
parts.push({
- articles: parseList($(SELECTOR_LIST).first(), $)
+ title: $title.text().trim(),
+ articles: parseList($list, $)
});
});
diff --git a/packages/gitbook-html/lib/totext.js b/packages/gitbook-html/lib/totext.js
index 13b1cd8..b1c94d4 100644
--- a/packages/gitbook-html/lib/totext.js
+++ b/packages/gitbook-html/lib/totext.js
@@ -123,6 +123,8 @@ ToText.prototype._summaryArticles = function(articles, level) {
ToText.prototype._summaryPart = function(part) {
var content = '';
+ if (part.title) content += this.onTitleStart(2) + this.onText(part.title) + this.onTitleEnd(2);
+
content += this._summaryArticles(part.articles);
content += this.onSection();
diff --git a/packages/gitbook-html/test/fixtures/SUMMARY.html b/packages/gitbook-html/test/fixtures/SUMMARY.html
index bae97f3..ec95da7 100755
--- a/packages/gitbook-html/test/fixtures/SUMMARY.html
+++ b/packages/gitbook-html/test/fixtures/SUMMARY.html
@@ -25,6 +25,8 @@
<li>Unfinished Chapter</li>
</ul>
+<h2>Part 2</h2>
+
<ul>
<li>
<a href="chapter-1/README.md">Chapter 1</a>
diff --git a/packages/gitbook-html/test/summary.js b/packages/gitbook-html/test/summary.js
index 4d06c32..02104cd 100755
--- a/packages/gitbook-html/test/summary.js
+++ b/packages/gitbook-html/test/summary.js
@@ -13,14 +13,26 @@ describe('Summary parsing', function () {
PART = LEXED.parts[0];
});
- it('should detect parts', function() {
- assert.equal(LEXED.parts.length, 3);
+ describe('Parts', function() {
+ it('should detect parts', function() {
+ assert.equal(LEXED.parts.length, 3);
+ });
+
+ it('should detect title', function() {
+ assert.equal(LEXED.parts[0].title, '');
+ assert.equal(LEXED.parts[1].title, 'Part 2');
+ assert.equal(LEXED.parts[2].title, '');
+ });
});
it('should detect chapters', function() {
assert.equal(PART.articles.length, 5);
});
+ it('should detect chapters in other parts', function() {
+ assert.equal(LEXED.parts[1].articles.length, 1);
+ });
+
it('should support articles', function() {
assert.equal(PART.articles[0].articles.length, 2);
assert.equal(PART.articles[1].articles.length, 0);