mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #1184 from omnivore-app/fix/html-to-text-error
fix/html to text error
This commit is contained in:
commit
277a01f9d6
1 changed files with 13 additions and 3 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue