2
0

🧑‍💻 Parse line breaks for plainText attributes

Closes #202
This commit is contained in:
Baptiste Arnaud
2023-01-02 10:41:06 +01:00
parent ec7481d002
commit bea1a6a3f8

View File

@ -1,13 +1,17 @@
import { Parser } from 'htmlparser2'
import { isNotEmpty } from 'utils'
export const parseHtmlStringToPlainText = (html: string): string => {
let label = ''
let plainText = ''
const parser = new Parser({
onopentag(name) {
if (name === 'div' && isNotEmpty(plainText)) plainText += '\n'
},
ontext(text) {
label += `${text}`
plainText += `${text}`
},
})
parser.write(html)
parser.end()
return label
return plainText
}