mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Check if top-level node has text content
This commit is contained in:
parent
d915d7a1e1
commit
3deed195f6
1 changed files with 12 additions and 2 deletions
|
|
@ -70,7 +70,7 @@ function parseDomTree(pageNode: Element) {
|
|||
}
|
||||
|
||||
function emit(textItems: string[], text: string) {
|
||||
textItems.push(text.trim())
|
||||
textItems.push(text)
|
||||
}
|
||||
|
||||
function cleanTextNode(textNode: ChildNode): string {
|
||||
|
|
@ -167,6 +167,16 @@ const endSsml = (): string => {
|
|||
return `</prosody></voice></speak>`
|
||||
}
|
||||
|
||||
const hasSignificantText = (node: ChildNode): boolean => {
|
||||
let text = ''
|
||||
for (const child of Array.from(node.childNodes)) {
|
||||
if (child.nodeType === 3 /* Node.TEXT_NODE */) {
|
||||
text += child.textContent
|
||||
}
|
||||
}
|
||||
return text.trim().length > 0
|
||||
}
|
||||
|
||||
export const ssmlItemText = (item: SSMLItem): string => {
|
||||
return [item.open, ...item.textItems, item.close].join('')
|
||||
}
|
||||
|
|
@ -198,7 +208,7 @@ export const htmlToSsml = (html: string, options: SSMLOptions): SSMLItem[] => {
|
|||
const textItems: string[] = []
|
||||
const node = parsedNodes[i - 2]
|
||||
|
||||
if (TOP_LEVEL_TAGS.includes(node.nodeName)) {
|
||||
if (TOP_LEVEL_TAGS.includes(node.nodeName) || hasSignificantText(node)) {
|
||||
i = emitElement(textItems, node, true)
|
||||
items.push({
|
||||
open: startSsml(node, options),
|
||||
|
|
|
|||
Loading…
Reference in a new issue