mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
+1
-1
@@ -32,7 +32,7 @@ export const textWalker = function* (x, func, filterFunc) {
|
|||||||
const walker = document.createTreeWalker(root, filter, { acceptNode: filterFunc || acceptNode })
|
const walker = document.createTreeWalker(root, filter, { acceptNode: filterFunc || acceptNode })
|
||||||
const walk = x.commonAncestorContainer ? walkRange : walkDocument
|
const walk = x.commonAncestorContainer ? walkRange : walkDocument
|
||||||
const nodes = walk(x, walker)
|
const nodes = walk(x, walker)
|
||||||
const strs = nodes.map(node => node.nodeValue)
|
const strs = nodes.map(node => node.nodeValue ?? '')
|
||||||
const makeRange = (startIndex, startOffset, endIndex, endOffset) => {
|
const makeRange = (startIndex, startOffset, endIndex, endOffset) => {
|
||||||
const range = document.createRange()
|
const range = document.createRange()
|
||||||
range.setStart(nodes[startIndex], startOffset)
|
range.setStart(nodes[startIndex], startOffset)
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ const fragmentToSSML = (fragment, inherited) => {
|
|||||||
if (!node) return
|
if (!node) return
|
||||||
if (node.nodeType === 3) return ssml.createTextNode(node.textContent)
|
if (node.nodeType === 3) return ssml.createTextNode(node.textContent)
|
||||||
if (node.nodeType === 4) return ssml.createCDATASection(node.textContent)
|
if (node.nodeType === 4) return ssml.createCDATASection(node.textContent)
|
||||||
if (node.nodeType !== 1) return
|
if (node.nodeType !== 1 && node.nodeType !== 11) return
|
||||||
|
|
||||||
let el
|
let el
|
||||||
const nodeName = node.nodeName.toLowerCase()
|
const nodeName = node.nodeName.toLowerCase()
|
||||||
@@ -66,15 +66,15 @@ const fragmentToSSML = (fragment, inherited) => {
|
|||||||
else if (nodeName === 'em' || nodeName === 'strong')
|
else if (nodeName === 'em' || nodeName === 'strong')
|
||||||
el = ssml.createElementNS(NS.SSML, 'emphasis')
|
el = ssml.createElementNS(NS.SSML, 'emphasis')
|
||||||
|
|
||||||
const lang = node.lang || node.getAttributeNS(NS.XML, 'lang')
|
const lang = node.lang || node.getAttributeNS?.(NS.XML, 'lang')
|
||||||
if (lang) {
|
if (lang) {
|
||||||
if (!el) el = ssml.createElementNS(NS.SSML, 'lang')
|
if (!el) el = ssml.createElementNS(NS.SSML, 'lang')
|
||||||
el.setAttributeNS(NS.XML, 'lang', lang)
|
el.setAttributeNS(NS.XML, 'lang', lang)
|
||||||
}
|
}
|
||||||
|
|
||||||
const alphabet = node.getAttributeNS(NS.SSML, 'alphabet') || inheritedAlphabet
|
const alphabet = node.getAttributeNS?.(NS.SSML, 'alphabet') || inheritedAlphabet
|
||||||
if (!el) {
|
if (!el) {
|
||||||
const ph = node.getAttributeNS(NS.SSML, 'ph')
|
const ph = node.getAttributeNS?.(NS.SSML, 'ph')
|
||||||
if (ph) {
|
if (ph) {
|
||||||
el = ssml.createElementNS(NS.SSML, 'phoneme')
|
el = ssml.createElementNS(NS.SSML, 'phoneme')
|
||||||
if (alphabet) el.setAttribute('alphabet', alphabet)
|
if (alphabet) el.setAttribute('alphabet', alphabet)
|
||||||
@@ -92,7 +92,7 @@ const fragmentToSSML = (fragment, inherited) => {
|
|||||||
}
|
}
|
||||||
return el
|
return el
|
||||||
}
|
}
|
||||||
convert(fragment.firstChild, ssml.documentElement, inherited.alphabet)
|
convert(fragment, ssml.documentElement, inherited.alphabet)
|
||||||
return ssml
|
return ssml
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user