( node: HljsNode | string, theme: Theme, parentScope: string | undefined, out: Block[], )
| 467 | } |
| 468 | |
| 469 | function flattenHljs( |
| 470 | node: HljsNode | string, |
| 471 | theme: Theme, |
| 472 | parentScope: string | undefined, |
| 473 | out: Block[], |
| 474 | ): void { |
| 475 | if (typeof node === 'string') { |
| 476 | const fg = scopeColor(parentScope, node, theme) |
| 477 | out.push([{ foreground: fg, background: theme.background }, node]) |
| 478 | return |
| 479 | } |
| 480 | const scope = node.scope ?? node.kind ?? parentScope |
| 481 | for (const child of node.children) { |
| 482 | flattenHljs(child, theme, scope, out) |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | // result.emitter is in the public HighlightResult type, but rootNode is |
| 487 | // internal to TokenTreeEmitter. Type guard validates the shape once so we |
no test coverage detected