summaryrefslogtreecommitdiff
path: root/odoo/tools
diff options
context:
space:
mode:
authorRémy Voet <ryv@odoo.com>2020-03-09 14:03:56 +0000
committerThibault Delavallée <tde@odoo.com>2020-03-12 13:54:32 +0000
commit974f512f5f5d3b9f80a8c3fcde290e4f55cf1230 (patch)
tree072718b0e00f0759ac0cc98dd2a5fe5ef0a3665a /odoo/tools
parentb1037eb2d1688607bfa928125361430948285715 (diff)
[IMP] tools: add a tool method to find if an html content is empty
In odoo empty html is not always completely empty. This tool method allow to consider html holding void tags as empty html. This happens notably when using the editor that may store <p><br><p> even if displayed content is void. Task ID 2126509 PR #41827
Diffstat (limited to 'odoo/tools')
-rw-r--r--odoo/tools/mail.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py
index 50467df606e..b6640da1240 100644
--- a/odoo/tools/mail.py
+++ b/odoo/tools/mail.py
@@ -254,6 +254,20 @@ def html_sanitize(src, silent=True, sanitize_tags=True, sanitize_attributes=Fals
# HTML/Text management
#----------------------------------------------------------
+def is_html_empty(html_content):
+ """Check if a html content is empty. If there are only formatting tags or
+ a void content return True. Famous use case if a '<p><br></p>' added by
+ some web editor.
+
+ :param str html_content: html content, coming from example from an HTML field
+ :returns: bool, True if no content found or if containing only void formatting tags
+ """
+ if not html_content:
+ return True
+ tag_re = re.compile(r'\<\s*\/?(?:p|div|span|br|b|i)\s*\>')
+ return not bool(re.sub(tag_re, '', html_content).strip())
+
+
def html_keep_url(text):
""" Transform the url into clickable link with <a/> tag """
idx = 0