Trim spaces in getPlainContent, prevent images from loading

fixes #834 closes #963
This commit is contained in:
Davis 2016-05-27 07:34:31 +09:30 committed by Toby Zerner
parent 500cdbbcb3
commit e41a427a6b
2 changed files with 10 additions and 4 deletions

View File

@ -31481,11 +31481,13 @@ System.register('flarum/utils/string', [], function (_export, _context) {
_export('slug', slug);
function getPlainContent(string) {
var dom = $('<div/>').html(string.replace(/(<\/p>|<br>)/g, '$1 &nbsp;'));
var html = string.replace(/(<\/p>|<br>)/g, '$1 &nbsp;').replace(/<img\b[^>]*>/ig, ' ');
var dom = $('<div/>').html(html);
dom.find(getPlainContent.removeSelectors.join(',')).remove();
return dom.text();
return dom.text().replace(/\s+/g, ' ').trim();
}
/**

View File

@ -34,11 +34,15 @@ export function slug(string) {
* @return {String}
*/
export function getPlainContent(string) {
const dom = $('<div/>').html(string.replace(/(<\/p>|<br>)/g, '$1 &nbsp;'));
const html = string
.replace(/(<\/p>|<br>)/g, '$1 &nbsp;')
.replace(/<img\b[^>]*>/ig, ' ');
const dom = $('<div/>').html(html);
dom.find(getPlainContent.removeSelectors.join(',')).remove();
return dom.text();
return dom.text().replace(/\s+/g, ' ').trim();
}
/**