From e41a427a6b9370e6468a7c3e38c9149aa6d50fe3 Mon Sep 17 00:00:00 2001 From: Davis Date: Fri, 27 May 2016 07:34:31 +0930 Subject: [PATCH] Trim spaces in getPlainContent, prevent images from loading fixes #834 closes #963 --- framework/core/js/forum/dist/app.js | 6 ++++-- framework/core/js/lib/utils/string.js | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/framework/core/js/forum/dist/app.js b/framework/core/js/forum/dist/app.js index 47b003f73..b2aa69779 100644 --- a/framework/core/js/forum/dist/app.js +++ b/framework/core/js/forum/dist/app.js @@ -31481,11 +31481,13 @@ System.register('flarum/utils/string', [], function (_export, _context) { _export('slug', slug); function getPlainContent(string) { - var dom = $('
').html(string.replace(/(<\/p>|
)/g, '$1  ')); + var html = string.replace(/(<\/p>|
)/g, '$1  ').replace(/]*>/ig, ' '); + + var dom = $('
').html(html); dom.find(getPlainContent.removeSelectors.join(',')).remove(); - return dom.text(); + return dom.text().replace(/\s+/g, ' ').trim(); } /** diff --git a/framework/core/js/lib/utils/string.js b/framework/core/js/lib/utils/string.js index d8d11d257..92ad98ae7 100644 --- a/framework/core/js/lib/utils/string.js +++ b/framework/core/js/lib/utils/string.js @@ -34,11 +34,15 @@ export function slug(string) { * @return {String} */ export function getPlainContent(string) { - const dom = $('
').html(string.replace(/(<\/p>|
)/g, '$1  ')); + const html = string + .replace(/(<\/p>|
)/g, '$1  ') + .replace(/]*>/ig, ' '); + + const dom = $('
').html(html); dom.find(getPlainContent.removeSelectors.join(',')).remove(); - return dom.text(); + return dom.text().replace(/\s+/g, ' ').trim(); } /**