bcf5a1bc34
refs #9178 * Add eslint deps, remove old lint deps * Add eslint config, remove old lint configs * Config for server and tests are different * Tweaked rules to suit us * Fix linting in codebase - lots of indent changes. * Fix a real broken test
20 lines
648 B
JavaScript
20 lines
648 B
JavaScript
var downsize = require('downsize');
|
|
|
|
function getExcerpt(html, truncateOptions) {
|
|
truncateOptions = truncateOptions || {};
|
|
// 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;
|