summaryrefslogtreecommitdiffstats
path: root/lib/page/html.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-25 15:43:55 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-25 15:43:55 +0100
commit327e90e8ec731352d659aa0ada810332fcd66a18 (patch)
tree2acdb2e1f7c42d91ff098b5cabfa4e57701756bc /lib/page/html.js
parent9253b764fad8452fb1cf0760be482b692fdfb728 (diff)
downloadgitbook-327e90e8ec731352d659aa0ada810332fcd66a18.zip
gitbook-327e90e8ec731352d659aa0ada810332fcd66a18.tar.gz
gitbook-327e90e8ec731352d659aa0ada810332fcd66a18.tar.bz2
Extract description from page's front matter
Fixes #1079 and #795
Diffstat (limited to 'lib/page/html.js')
-rw-r--r--lib/page/html.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/page/html.js b/lib/page/html.js
index bd9ec91..bce6cd2 100644
--- a/lib/page/html.js
+++ b/lib/page/html.js
@@ -14,6 +14,9 @@ function HTMLPipeline(htmlString, opts) {
_.bindAll(this);
this.opts = _.defaults(opts || {}, {
+ // Called once the description has been found
+ onDescription: function(description) { },
+
// Calcul new href for a relative link
onRelativeLink: _.identity,
@@ -178,11 +181,21 @@ HTMLPipeline.prototype.applyAnnotations = function() {
});
};
+// Extract page description from html
+// This can totally be improved
+HTMLPipeline.prototype.extractDescription = function() {
+ var $p = this.$('p').first();
+ var description = $p.text().trim().slice(0, 155);
+
+ this.opts.onDescription(description);
+};
+
// Write content to the pipeline
HTMLPipeline.prototype.output = function() {
var that = this;
return Promise()
+ .then(this.extractDescription)
.then(this.transformImages)
.then(this.transformHeadings)
.then(this.transformCodeBlocks)