summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSoreine <soreine.plume@gmail.com>2016-06-10 15:57:15 +0200
committerSamy Pessé <samypesse@gmail.com>2016-12-22 12:32:21 +0100
commit1c663121313b7597e2f1fd403d6e4e9e56153acd (patch)
treea0ea661a8d2b674dc5caa7b1e5b88394272d37e8
parent22ea09d9a6e6a56eefd508015b475d84999b01de (diff)
downloadgitbook-1c663121313b7597e2f1fd403d6e4e9e56153acd.zip
gitbook-1c663121313b7597e2f1fd403d6e4e9e56153acd.tar.gz
gitbook-1c663121313b7597e2f1fd403d6e4e9e56153acd.tar.bz2
Fix last empty part not parsed
-rwxr-xr-xpackages/gitbook-html/lib/summary.js5
-rw-r--r--packages/gitbook-html/test/fixtures/SUMMARY-EMPTY.html8
-rwxr-xr-xpackages/gitbook-html/test/summary.js26
3 files changed, 33 insertions, 6 deletions
diff --git a/packages/gitbook-html/lib/summary.js b/packages/gitbook-html/lib/summary.js
index f458d1d..4b263c9 100755
--- a/packages/gitbook-html/lib/summary.js
+++ b/packages/gitbook-html/lib/summary.js
@@ -97,6 +97,11 @@ function findParts($parent, $) {
}
});
+ // Last part might be empty
+ if (previousPart !== null) {
+ parts.push(previousPart);
+ }
+
return parts;
}
diff --git a/packages/gitbook-html/test/fixtures/SUMMARY-EMPTY.html b/packages/gitbook-html/test/fixtures/SUMMARY-EMPTY.html
index 03579a1..9d4397b 100644
--- a/packages/gitbook-html/test/fixtures/SUMMARY-EMPTY.html
+++ b/packages/gitbook-html/test/fixtures/SUMMARY-EMPTY.html
@@ -1,5 +1,7 @@
<h1>Summary</h1>
+<h2>First empty part</h2>
+
<h2>Part 1</h2>
<ul>
@@ -8,6 +10,8 @@
<li><a href="chapter-3/README.md">Chapter 3</a></li>
</ul>
+<!-- Untitled part here -->
+
<ul>
<li><a href="chapter-1/README.md">Chapter for untitled part</a></li>
</ul>
@@ -19,3 +23,7 @@
<ul>
<li><a href="chapter-1/README.md">Chapter for Part 2</a></li>
</ul>
+
+<h2>Penultimate empty part</h2>
+
+<h2>Last empty part</h2>
diff --git a/packages/gitbook-html/test/summary.js b/packages/gitbook-html/test/summary.js
index 9c064f9..03be73f 100755
--- a/packages/gitbook-html/test/summary.js
+++ b/packages/gitbook-html/test/summary.js
@@ -6,6 +6,7 @@ var summary = require('../').summary;
describe('Summary parsing', function () {
var LEXED, PART;
+ var LEXED_EMPTY;
before(function() {
var CONTENT = fs.readFileSync(
@@ -13,6 +14,9 @@ describe('Summary parsing', function () {
LEXED = summary(CONTENT);
PART = LEXED.parts[0];
+ var CONTENT_EMPTY = fs.readFileSync(
+ path.join(__dirname, './fixtures/SUMMARY-EMPTY.html'), 'utf8');
+ LEXED_EMPTY = summary(CONTENT_EMPTY);
});
describe('Parts', function() {
@@ -27,12 +31,22 @@ describe('Summary parsing', function () {
});
it('should detect empty parts', function() {
- var CONTENT_EMPTY = fs.readFileSync(
- path.join(__dirname, './fixtures/SUMMARY-EMPTY.html'), 'utf8');
- var LEXED_EMPTY = summary(CONTENT_EMPTY);
-
- assert.equal(LEXED_EMPTY.parts.length, 4);
- assert.equal(LEXED_EMPTY.parts[2].title, 'Empty part');
+ var partTitles = LEXED_EMPTY.parts.map(function (part) {
+ return part.title;
+ });
+ var expectedTitles = [
+ 'First empty part',
+ 'Part 1',
+ '',
+ 'Empty part',
+ 'Part 2',
+ 'Penultimate empty part',
+ 'Last empty part'
+ ];
+ assert.equal(LEXED_EMPTY.parts.length, 7);
+ expectedTitles.forEach(function (title, index) {
+ assert.equal(partTitles[index], title);
+ });
});
});