diff --git a/web/components/notifications/notification-card.tsx b/web/components/notifications/notification-card.tsx index 45a2ab2b2..f8a2b1700 100644 --- a/web/components/notifications/notification-card.tsx +++ b/web/components/notifications/notification-card.tsx @@ -11,7 +11,7 @@ import { ArchiveIcon, CustomMenu, Tooltip } from "@plane/ui"; import { ArchiveRestore, Clock, MessageSquare, User2 } from "lucide-react"; // helper -import { stripHTML, replaceUnderscoreIfSnakeCase, truncateText } from "helpers/string.helper"; +import { replaceUnderscoreIfSnakeCase, truncateText, stripAndTruncateHTML } from "helpers/string.helper"; import { formatDateDistance, render12HourFormatTime, @@ -115,10 +115,10 @@ export const NotificationCard: React.FC = (props) => { renderShortDateWithYearFormat(notification.data.issue_activity.new_value) ) : notification.data.issue_activity.field === "attachment" ? ( "the issue" - ) : stripHTML(notification.data.issue_activity.new_value).length > 55 ? ( - stripHTML(notification.data.issue_activity.new_value).slice(0, 50) + "..." + ) : notification.data.issue_activity.field === "description" ? ( + stripAndTruncateHTML(notification.data.issue_activity.new_value, 55) ) : ( - stripHTML(notification.data.issue_activity.new_value) + notification.data.issue_activity.new_value ) ) : ( diff --git a/web/helpers/string.helper.ts b/web/helpers/string.helper.ts index 6596f1d69..29f414200 100644 --- a/web/helpers/string.helper.ts +++ b/web/helpers/string.helper.ts @@ -111,11 +111,20 @@ export const getFirstCharacters = (str: string) => { */ export const stripHTML = (html: string) => { - const tmp = document.createElement("DIV"); - tmp.innerHTML = html; - return tmp.textContent || tmp.innerText || ""; + const strippedText = html.replace(/]*>[\s\S]*?<\/script>/gi, ""); // Remove script tags + return strippedText.replace(/<[^>]*>/g, ""); // Remove all other HTML tags }; +/** + * + * @example: + * const html = "

Some text

"; + * const text = stripAndTruncateHTML(html); + * console.log(text); // Some text + */ + +export const stripAndTruncateHTML = (html: string, length: number = 55) => truncateText(stripHTML(html), length); + /** * @description: This function return number count in string if number is more than 100 then it will return 99+ * @param {number} number