Browse Source

add try catch html to text

main
matthew 2 years ago
parent
commit
8de8b8b65b
  1. 6
      searching-front/services/modules/parser/helpers.ts

6
searching-front/services/modules/parser/helpers.ts

@ -12,12 +12,16 @@ const convert = (html: string) =>
listStyle: "linebreak",
})
export const htmlToText = (html: string) => {
try {
const text = convert(html)
return text
.replaceAll(/&\w*;/g, "")
.replaceAll(/<!--\s?(.|\R|\s)*?-->/g, "")
.replaceAll(/<.*><\/.*>/g, "")
} catch (e) {
console.log("htmlToText", e)
return ""
}
}
export const SHOULD_NOT_PARSE = "SHOULD_NOT_PARSE"

Loading…
Cancel
Save