fix: catch exceptions in HTML parser (#994)

zio/stable
Vjacheslav Trushkin 2023-01-12 13:13:20 +02:00 committed by GitHub
parent 70a4475eac
commit 79753fd508
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -106,9 +106,15 @@ export function convertMastodonHTML(html: string, customEmojis: Record<string, m
} }
export function htmlToText(html: string) { export function htmlToText(html: string) {
try {
const tree = parse(html) const tree = parse(html)
return (tree.children as Node[]).map(n => treeToText(n)).join('').trim() return (tree.children as Node[]).map(n => treeToText(n)).join('').trim()
} }
catch (err) {
console.error(err)
return ''
}
}
export function treeToText(input: Node): string { export function treeToText(input: Node): string {
let pre = '' let pre = ''