fix: catch exceptions in HTML parser (#994)
This commit is contained in:
parent
70a4475eac
commit
79753fd508
|
@ -106,9 +106,15 @@ export function convertMastodonHTML(html: string, customEmojis: Record<string, m
|
|||
}
|
||||
|
||||
export function htmlToText(html: string) {
|
||||
try {
|
||||
const tree = parse(html)
|
||||
return (tree.children as Node[]).map(n => treeToText(n)).join('').trim()
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err)
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
export function treeToText(input: Node): string {
|
||||
let pre = ''
|
||||
|
|
Loading…
Reference in a new issue