tooot/src/helpers/removeHTML.ts

22 lines
414 B
TypeScript

import htmlparser2 from 'htmlparser2-without-node-native'
const removeHTML = (text: string): string => {
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
}
export default removeHTML