// # Excerpt Helper
// Usage: `{{excerpt}}`, `{{excerpt words="50"}}`, `{{excerpt characters="256"}}`
//
// Attempts to remove all HTML from the string, and then shortens the result according to the provided option.
//
// Defaults to words="50"

var hbs             = require('express-hbs'),
    _               = require('lodash'),
    downsize        = require('downsize'),
    excerpt;

excerpt = function (options) {
    var truncateOptions = (options || {}).hash || {},
        excerpt;

    truncateOptions = _.pick(truncateOptions, ['words', 'characters']);
    _.keys(truncateOptions).map(function (key) {
        truncateOptions[key] = parseInt(truncateOptions[key], 10);
    });

    /*jslint regexp:true */
    excerpt = String(this.html);
    // Strip inline and bottom footnotes
    excerpt = excerpt.replace(/<a href="#fn.*?rel="footnote">.*?<\/a>/gi, '');
    excerpt = excerpt.replace(/<div class="footnotes"><ol>.*?<\/ol><\/div>/, '');
    // Strip other html
    excerpt = excerpt.replace(/<\/?[^>]+>/gi, '');
    excerpt = excerpt.replace(/(\r\n|\n|\r)+/gm, ' ');
    /*jslint regexp:false */

    if (!truncateOptions.words && !truncateOptions.characters) {
        truncateOptions.words = 50;
    }

    return new hbs.handlebars.SafeString(
        downsize(excerpt, truncateOptions)
    );
};

module.exports = excerpt;

@@ -558,135 +558,362 @@
 ers'
-%5D);%0A    _.keys(truncateOptions).map(function (key) %7B%0A        truncateOptions%5Bkey%5D = parseInt(truncateOptions%5Bkey%5D, 10);%0A    %7D);
+, 'round', 'append'%5D);%0A    %5B'words', 'characters'%5D.map(function (key) %7B%0A        if (!truncateOptions%5Bkey%5D) %7B return; %7D%0A        truncateOptions%5Bkey%5D = parseInt(truncateOptions%5Bkey%5D, 10);%0A    %7D);%0A    truncateOptions.round = !!truncateOptions.round;%0A%0A    if (!truncateOptions.words && !truncateOptions.characters) %7B%0A        truncateOptions.words = 50;%0A    %7D
 %0A%0A  
@@ -1169,24 +1169,25 @@
 div%3E/, '');%0A
+%0A
     // Strip
@@ -1198,16 +1198,54 @@
 er html%0A
+    if (!truncateOptions.round) %7B%0A    
     exce
@@ -1279,32 +1279,36 @@
 %5B%5E%3E%5D+%3E/gi, '');%0A
+    
     excerpt = ex
@@ -1354,231 +1354,355 @@
     
-/*jslint regexp:false */%0A%0A    if (!truncateOptions.words && !truncateOptions.characters) %7B%0A        truncateOptions.words = 50;%0A    %7D%0A%0A    return new hbs.handlebars.SafeString(%0A        downsize(excerpt, truncateOptions)%0A    
+    excerpt = downsize(excerpt, truncateOptions);%0A    %7D%0A    else %7B%0A        excerpt = downsize(excerpt, truncateOptions);%0A        // Strip other html%0A        excerpt = excerpt.replace(/%3C%5C/?%5B%5E%3E%5D+%3E/gi, '');%0A        excerpt = excerpt.replace(/(%5Cr%5Cn%7C%5Cn%7C%5Cr)+/gm, ' ');%0A    %7D%0A    /*jslint regexp:false */%0A%0A    return new hbs.handlebars.SafeString(excerpt
 );%0A%7D

Allow use of round and append downsize options for excerpt helper