1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
Files
tooot/src/utils/helpers/removeHTML.ts
2023-01-16 18:56:15 +01:00

24 lines
454 B
TypeScript

import * as htmlparser2 from 'htmlparser2'
const removeHTML = (text: string): string => {
if (!text) return ''
let raw: string = ''
const parser = new htmlparser2.Parser({
ontext: (text: string) => {
raw = raw + text
},
onclosetag: (tag: string) => {
if (['p', 'br'].includes(tag)) raw = raw + `\n`
}
})
parser.write(text)
parser.end()
return raw.replace(new RegExp(/\s$/), '')
}
export default removeHTML