14 lines
411 B
TypeScript
14 lines
411 B
TypeScript
/** Visible text of stored HTML, without pulling in the sanitizer. */
|
|
export function htmlToPlain(value: string): string {
|
|
return value
|
|
.replace(/<br\s*\/?>/gi, " ")
|
|
.replace(/<\/(p|div|h2|h3|h4|li|blockquote)>/gi, " ")
|
|
.replace(/<[^>]+>/g, "")
|
|
.replace(/ /g, " ")
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/\s+/g, " ")
|
|
.trim();
|
|
}
|