update: escape the html tag from announcmetn

This commit is contained in:
mahyargdz
2025-08-28 09:45:38 +03:30
parent 2bb6859afc
commit 9869e603d3
2 changed files with 18 additions and 2 deletions
+16 -1
View File
@@ -1,4 +1,4 @@
export function truncateIfLong(str: string, maxLength = 30): string {
export function truncateIfLong(str: string, maxLength = 35): string {
if (typeof str !== "string") return str;
return str.length > maxLength ? str.slice(0, maxLength) + "..." : str;
}
@@ -18,3 +18,18 @@ export function randomizeCase(str: string): string {
})
.join("");
}
export function stripHtmlTags(str: string): string {
if (typeof str !== "string") return str;
// Remove HTML tags and decode common HTML entities
return str
.replace(/<[^>]*>/g, "") // Remove all HTML tags
.replace(/&nbsp;/g, " ") // Replace non-breaking spaces
.replace(/&amp;/g, "&") // Replace ampersand entities
.replace(/&lt;/g, "<") // Replace less than entities
.replace(/&gt;/g, ">") // Replace greater than entities
.replace(/&quot;/g, '"') // Replace quote entities
.replace(/&#39;/g, "'") // Replace apostrophe entities
.trim(); // Remove leading/trailing whitespace
}