summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-html/lib/totext.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-05-02 16:12:07 +0200
committerSamy Pessé <samypesse@gmail.com>2016-12-22 12:32:17 +0100
commitc3a417a9834ba3c25ceb20a3cb650fa0384c60d0 (patch)
treebdbffac34a15636265e834b9bf0c484054426135 /packages/gitbook-html/lib/totext.js
parent9e88003d7373e2e7efac862494a9a0db4847f617 (diff)
downloadgitbook-c3a417a9834ba3c25ceb20a3cb650fa0384c60d0.zip
gitbook-c3a417a9834ba3c25ceb20a3cb650fa0384c60d0.tar.gz
gitbook-c3a417a9834ba3c25ceb20a3cb650fa0384c60d0.tar.bz2
Adapt for gitbook v3
Diffstat (limited to 'packages/gitbook-html/lib/totext.js')
-rw-r--r--packages/gitbook-html/lib/totext.js22
1 files changed, 20 insertions, 2 deletions
diff --git a/packages/gitbook-html/lib/totext.js b/packages/gitbook-html/lib/totext.js
index 49762d9..64d4898 100644
--- a/packages/gitbook-html/lib/totext.js
+++ b/packages/gitbook-html/lib/totext.js
@@ -1,5 +1,11 @@
var _ = require('lodash');
+/*
+ This class is extended by gitbook-markdown and gitbook-asciidoc
+ to generate back markdown/asciidoc from GitBook metadata.
+*/
+
+
function ToText(markup) {
_.extend(this, markup || {});
_.bindAll(this);
@@ -14,6 +20,10 @@ ToText.prototype.onText = function(text) {
return text;
};
+ToText.prototype.onHR = function() {
+ return '<hr />';
+};
+
// ---- TITLES
ToText.prototype.onTitleStart = function(level) {
@@ -126,7 +136,6 @@ ToText.prototype._summaryPart = function(part) {
if (part.title) content += this.onTitleStart(2) + this.onText(part.title) + this.onTitleEnd(2);
content += this._summaryArticles(part.articles);
- content += this.onSection();
return content;
};
@@ -136,8 +145,17 @@ ToText.prototype.summary = function(summary) {
content += this.onTitleStart(1) + this.onText('Summary') + this.onTitleEnd(1);
content += this.onSection();
- _.each(summary.parts, function(part) {
+ _.each(summary.parts, function(part, i) {
+ var next = summary.parts[i + 1];
+
content += this._summaryPart(part);
+
+ if (next && !next.title) {
+ content += this.onHR();
+ } else {
+ content += this.onSection();
+ }
+
}, this);
return content;