(node: Element)
| 225 | |
| 226 | // Mutually recursive functions for inline serialization |
| 227 | function serializeChildren(node: Element): string { |
| 228 | const children = Array.from(node.childNodes); |
| 229 | // eslint-disable-next-line @typescript-eslint/no-use-before-define |
| 230 | const parts = children.map((child) => serializeInline(child)); |
| 231 | |
| 232 | return parts |
| 233 | .map((part, index) => { |
| 234 | const child = children[index]; |
| 235 | const isIntraword = |
| 236 | (isWordChar(parts[index - 1]?.slice(-1)) && !/^\s/.test(part)) || |
| 237 | (isWordChar(parts[index + 1]?.charAt(0)) && !/\s$/.test(part)); |
| 238 | |
| 239 | if (!isItalicElement(child) || !isIntraword) { |
| 240 | return part; |
| 241 | } |
| 242 | |
| 243 | return wrapLines(serializeChildren(child), '*'); |
| 244 | }) |
| 245 | .join(''); |
| 246 | } |
| 247 | |
| 248 | function serializeInline(node: Node): string { |
| 249 | if (node.nodeType === Node.TEXT_NODE) { |
no test coverage detected