mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add idx and voice to SSMLItem
This commit is contained in:
parent
33cf975b0e
commit
7ce7e28e3f
1 changed files with 6 additions and 19 deletions
|
|
@ -4,13 +4,6 @@ import * as _ from 'underscore'
|
|||
// this code needs to be kept in sync with the
|
||||
// frontend code in: useReadingProgressAnchor
|
||||
|
||||
export interface Utterance {
|
||||
wordOffset: number
|
||||
voice?: string
|
||||
words: string[]
|
||||
text: string
|
||||
}
|
||||
|
||||
const ANCHOR_ELEMENTS_BLOCKED_ATTRIBUTES = [
|
||||
'omnivore-highlight-id',
|
||||
'data-twitter-tweet-id',
|
||||
|
|
@ -151,6 +144,8 @@ export type SSMLItem = {
|
|||
open: string
|
||||
close: string
|
||||
textItems: string[]
|
||||
idx: number
|
||||
voice?: string
|
||||
}
|
||||
|
||||
export type SSMLOptions = {
|
||||
|
|
@ -202,14 +197,6 @@ export const htmlToSsmlItems = (
|
|||
}
|
||||
|
||||
const parsedNodes = parseDomTree(body)
|
||||
Array.from(parsedNodes).map((n) =>
|
||||
console.log(
|
||||
n.nodeName,
|
||||
n.getAttribute('data-omnivore-anchor-idx'),
|
||||
n.getAttribute('class')
|
||||
)
|
||||
)
|
||||
|
||||
if (parsedNodes.length < 1) {
|
||||
throw new Error('No HTML nodes found')
|
||||
}
|
||||
|
|
@ -220,18 +207,18 @@ export const htmlToSsmlItems = (
|
|||
const node = parsedNodes[i - 2]
|
||||
|
||||
if (TOP_LEVEL_TAGS.includes(node.nodeName) || hasSignificantText(node)) {
|
||||
const idx = i
|
||||
i = emitElement(textItems, node, true)
|
||||
items.push({
|
||||
open: startSsml(node, options),
|
||||
close: endSsml(),
|
||||
textItems: textItems,
|
||||
idx,
|
||||
voice:
|
||||
node.nodeName === 'BLOCKQUOTE' ? options.secondaryVoice : undefined,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
export const htmlToSsml = (html: string, options: SSMLOptions): string[] => {
|
||||
return htmlToSsmlItems(html, options).map(ssmlItemText)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue