The HTML string to convert
The ASCII string
htmlToAscii("<p>Hello <b>world</b></p><p>This is a test</p>")
// Returns "Hello world\nThis is a test"
export function htmlToAscii(html: string): string {
return html
.replace(/<\/p>/gi, "\n")
.replace(/<br\s*\/?>/gi, "\n")
.replace(/<[^>]+>/g, "")
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/ /g, " ")
.replace(/"/g, '"')
.replace(/'/g, "'")
.trim();
}
Converts HTML to ASCII.