mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: html sensitization function (#2552)
This commit is contained in:
parent
fc82d6fc23
commit
8cc61bc427
@ -11,7 +11,7 @@ import { ArchiveIcon, CustomMenu, Tooltip } from "@plane/ui";
|
|||||||
import { ArchiveRestore, Clock, MessageSquare, User2 } from "lucide-react";
|
import { ArchiveRestore, Clock, MessageSquare, User2 } from "lucide-react";
|
||||||
|
|
||||||
// helper
|
// helper
|
||||||
import { stripHTML, replaceUnderscoreIfSnakeCase, truncateText } from "helpers/string.helper";
|
import { replaceUnderscoreIfSnakeCase, truncateText, stripAndTruncateHTML } from "helpers/string.helper";
|
||||||
import {
|
import {
|
||||||
formatDateDistance,
|
formatDateDistance,
|
||||||
render12HourFormatTime,
|
render12HourFormatTime,
|
||||||
@ -115,10 +115,10 @@ export const NotificationCard: React.FC<NotificationCardProps> = (props) => {
|
|||||||
renderShortDateWithYearFormat(notification.data.issue_activity.new_value)
|
renderShortDateWithYearFormat(notification.data.issue_activity.new_value)
|
||||||
) : notification.data.issue_activity.field === "attachment" ? (
|
) : notification.data.issue_activity.field === "attachment" ? (
|
||||||
"the issue"
|
"the issue"
|
||||||
) : stripHTML(notification.data.issue_activity.new_value).length > 55 ? (
|
) : notification.data.issue_activity.field === "description" ? (
|
||||||
stripHTML(notification.data.issue_activity.new_value).slice(0, 50) + "..."
|
stripAndTruncateHTML(notification.data.issue_activity.new_value, 55)
|
||||||
) : (
|
) : (
|
||||||
stripHTML(notification.data.issue_activity.new_value)
|
notification.data.issue_activity.new_value
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<span>
|
<span>
|
||||||
|
@ -111,11 +111,20 @@ export const getFirstCharacters = (str: string) => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const stripHTML = (html: string) => {
|
export const stripHTML = (html: string) => {
|
||||||
const tmp = document.createElement("DIV");
|
const strippedText = html.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, ""); // Remove script tags
|
||||||
tmp.innerHTML = html;
|
return strippedText.replace(/<[^>]*>/g, ""); // Remove all other HTML tags
|
||||||
return tmp.textContent || tmp.innerText || "";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @example:
|
||||||
|
* const html = "<p>Some text</p>";
|
||||||
|
* 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+
|
* @description: This function return number count in string if number is more than 100 then it will return 99+
|
||||||
* @param {number} number
|
* @param {number} number
|
||||||
|
Loading…
Reference in New Issue
Block a user