From 9b05ec4e3085381a2a76359879c6f70e27c549f3 Mon Sep 17 00:00:00 2001 From: Nikhil Kothari Date: Sun, 28 Jan 2024 20:02:47 +0530 Subject: [PATCH] fix: Convert HTML instead of stripping html tags --- raven/patches.txt | 2 +- .../v1_3/update_all_messages_to_include_message_content.py | 6 ++---- .../raven_messaging/doctype/raven_message/raven_message.py | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/raven/patches.txt b/raven/patches.txt index e8b60c652..ad1b343a6 100644 --- a/raven/patches.txt +++ b/raven/patches.txt @@ -3,4 +3,4 @@ [post_model_sync] raven.patches.v1_2.create_raven_users raven.patches.v1_3.create_raven_message_indexes #23 -raven.patches.v1_3.update_all_messages_to_include_message_content #1 \ No newline at end of file +raven.patches.v1_3.update_all_messages_to_include_message_content #2 \ No newline at end of file diff --git a/raven/patches/v1_3/update_all_messages_to_include_message_content.py b/raven/patches/v1_3/update_all_messages_to_include_message_content.py index 30c69b3ff..dc3c60dda 100644 --- a/raven/patches/v1_3/update_all_messages_to_include_message_content.py +++ b/raven/patches/v1_3/update_all_messages_to_include_message_content.py @@ -1,6 +1,5 @@ import frappe -from frappe.utils import strip_html_tags - +from frappe.core.utils import html2text def execute(): update_old_messages_to_include_message_content() @@ -18,8 +17,7 @@ def update_old_messages_to_include_message_content(): 'name', 'text', 'message_type']) for message in messages: if message.text: - cleaned_text = strip_html_tags(message.text).replace( - '\ufeff', '').replace(' ', ' ') + cleaned_text = html2text(message.text) content = cleaned_text frappe.db.set_value( 'Raven Message', message.name, 'content', content) diff --git a/raven/raven_messaging/doctype/raven_message/raven_message.py b/raven/raven_messaging/doctype/raven_message/raven_message.py index d738b53b2..833f6da5c 100644 --- a/raven/raven_messaging/doctype/raven_message/raven_message.py +++ b/raven/raven_messaging/doctype/raven_message/raven_message.py @@ -3,9 +3,8 @@ import frappe from frappe import _ from frappe.model.document import Document -from frappe.utils import strip_html_tags from raven.api.raven_message import track_visit - +from frappe.core.utils import html2text class RavenMessage(Document): # begin: auto-generated types @@ -37,8 +36,7 @@ class RavenMessage(Document): def before_validate(self): try: if self.text: - self.content = strip_html_tags(self.text).replace( - '\ufeff', '').replace(' ', ' ') + self.content = html2text(self.text) except Exception: pass def validate(self):