( children: (HastNode | HastTextNode)[], key: string, links?: Links )
| 365 | } |
| 366 | |
| 367 | function renderChildren( |
| 368 | children: (HastNode | HastTextNode)[], |
| 369 | key: string, |
| 370 | links?: Links |
| 371 | ): Token[] { |
| 372 | let childArray: Token[] = []; |
| 373 | let type = -1; |
| 374 | let stringIndex = -1; |
| 375 | for (let [i, child] of children.entries()) { |
| 376 | let indent = |
| 377 | i === 1 && stringIndex >= 0 && /^\s+$/.test(childArray[stringIndex] as string) |
| 378 | ? (childArray[stringIndex] as string) |
| 379 | : ''; |
| 380 | let childNode = renderHast(child, `${key}.${i}`, links, indent); |
| 381 | let childNodes = Array.isArray(childNode) ? childNode : [childNode]; |
| 382 | let childIndex = 0; |
| 383 | while (childIndex < childNodes.length) { |
| 384 | let child = childNodes[childIndex++]; |
| 385 | let childType = -1; |
| 386 | if (typeof child === 'number') { |
| 387 | // A number represents a token type. Consume the next value. |
| 388 | childType = child; |
| 389 | child = childNodes[childIndex++]; |
| 390 | if (childType !== type) { |
| 391 | childArray.push(childType); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | // If this is a string, either append to the previous string if it is |
| 396 | // the same token type, or push a new string. |
| 397 | if (typeof child === 'string') { |
| 398 | if (childType !== type) { |
| 399 | type = childType; |
| 400 | stringIndex = childArray.length; |
| 401 | childArray.push(child); |
| 402 | } else if (stringIndex >= 0) { |
| 403 | childArray[stringIndex] += child; |
| 404 | } else { |
| 405 | stringIndex = childArray.length; |
| 406 | childArray.push(child); |
| 407 | } |
| 408 | } else { |
| 409 | type = -1; |
| 410 | stringIndex = -1; |
| 411 | childArray.push(child); |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | return childArray; |
| 417 | } |
| 418 | |
| 419 | function text(node) { |
| 420 | if (node.type === 'text') { |
no test coverage detected