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