update: escape the html tag from announcmetn
This commit is contained in:
@@ -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(/ /g, " ") // Replace non-breaking spaces
|
||||
.replace(/&/g, "&") // Replace ampersand entities
|
||||
.replace(/</g, "<") // Replace less than entities
|
||||
.replace(/>/g, ">") // Replace greater than entities
|
||||
.replace(/"/g, '"') // Replace quote entities
|
||||
.replace(/'/g, "'") // Replace apostrophe entities
|
||||
.trim(); // Remove leading/trailing whitespace
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user