ai-tube / src /lib /stripHtml.ts
jbilcke-hf's picture
jbilcke-hf HF staff
we can now post comments
38d787b
raw
history blame
455 Bytes
export function stripHtml(input: string) {
try {
return (
`${input || ""}`
.replace(/<style[^>]*>.*<\/style>/g, '')
// Remove script tags and content
.replace(/<script[^>]*>.*<\/script>/g, '')
// Remove all opening, closing and orphan HTML tags
.replace(/<[^>]+>/g, '')
// Remove leading spaces and repeated CR/LF
.replace(/([\r\n]+ +)+/g, '')
)
} catch (err) {
return ""
}
}