diff options
Diffstat (limited to 'packages/gitbook-html/lib/totext.js')
-rw-r--r-- | packages/gitbook-html/lib/totext.js | 22 |
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; |