Browse Source

add try catch html to text

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

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

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

Loading…
Cancel
Save