From c770fb90142d01667d92ae769382ecda3d7e23c8 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Mon, 1 Oct 2018 17:49:55 +0200 Subject: [PATCH] MOBILE-2611 utils: Function to check whether HTML content is blank --- src/providers/utils/text.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/providers/utils/text.ts b/src/providers/utils/text.ts index 6fa91d8be..3ee32224e 100644 --- a/src/providers/utils/text.ts +++ b/src/providers/utils/text.ts @@ -427,6 +427,23 @@ export class CoreTextUtilsProvider { return /<[a-z][\s\S]*>/i.test(text); } + /** + * Check if HTML content is blank. + * + * @param {string} content HTML content. + * @return {boolean} True if the string does not contain actual content: text, images, etc. + */ + htmlIsBlank(content: string): boolean { + if (!content) { + return true; + } + + const div = document.createElement('div'); + div.innerHTML = content; + + return div.textContent === '' && div.querySelector('img, object, hr') === null; + } + /** * Check if a text contains Unicode long chars. * Using as threshold Hex value D800