Merge pull request #1184 from omnivore-app/fix/html-to-text-error

fix/html to text error
This commit is contained in:
Hongbo Wu 2022-09-12 11:43:57 +08:00 committed by GitHub
commit 277a01f9d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -273,9 +273,19 @@ const textToUtterance = ({
voice?: string
isHtml?: boolean
}): Utterance => {
const text = textItems.join('')
const plainText = isHtml ? htmlToText(text, { wordwrap: false }) : text
const wordCount = tokenizer.tokenize(plainText).length
const text = stripEmojis(textItems.join(''))
let textWithWordOffset = text
if (isHtml) {
try {
textWithWordOffset = htmlToText(text, { wordwrap: false })
} catch (err) {
console.error('Unable to convert HTML to text', { text, err })
textWithWordOffset =
parseHTML(text).document.documentElement.textContent ?? text
console.debug('Converted HTML to text', { textWithWordOffset })
}
}
const wordCount = tokenizer.tokenize(textWithWordOffset).length
return {
idx,
text,