2016-01-17 13:07:52 +03:00
|
|
|
var downsize = require('downsize');
|
|
|
|
|
|
|
|
function getExcerpt(html, truncateOptions) {
|
2016-02-18 14:47:08 +03:00
|
|
|
truncateOptions = truncateOptions || {};
|
2016-01-17 13:07:52 +03:00
|
|
|
// Strip inline and bottom footnotes
|
|
|
|
var excerpt = html.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, ' ');
|
|
|
|
|
|
|
|
if (!truncateOptions.words && !truncateOptions.characters) {
|
|
|
|
truncateOptions.words = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
return downsize(excerpt, truncateOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getExcerpt;
|