* Squash text nodes into a plain string (without styles). * Used for text measurement in layout calculations.
(node: DOMElement)
| 67 | * Used for text measurement in layout calculations. |
| 68 | */ |
| 69 | function squashTextNodes(node: DOMElement): string { |
| 70 | let text = '' |
| 71 | |
| 72 | for (const childNode of node.childNodes) { |
| 73 | if (childNode === undefined) { |
| 74 | continue |
| 75 | } |
| 76 | |
| 77 | if (childNode.nodeName === '#text') { |
| 78 | text += childNode.nodeValue |
| 79 | } else if ( |
| 80 | childNode.nodeName === 'ink-text' || |
| 81 | childNode.nodeName === 'ink-virtual-text' |
| 82 | ) { |
| 83 | text += squashTextNodes(childNode) |
| 84 | } else if (childNode.nodeName === 'ink-link') { |
| 85 | text += squashTextNodes(childNode) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return text |
| 90 | } |
| 91 | |
| 92 | export default squashTextNodes |
| 93 |