| 476 | } |
| 477 | |
| 478 | const renderCodeBlock = (code: Code, state: RenderState): ReactNode[] => { |
| 479 | const { palette, nextKey } = state |
| 480 | const lines = code.value.split('\n') |
| 481 | const nodes: ReactNode[] = [] |
| 482 | |
| 483 | if (code.lang) { |
| 484 | nodes.push( |
| 485 | <span key={nextKey()} fg={palette.codeHeaderFg}> |
| 486 | {`// ${code.lang}`} |
| 487 | </span>, |
| 488 | '\n', |
| 489 | ) |
| 490 | } |
| 491 | |
| 492 | lines.forEach((line, index) => { |
| 493 | const displayLine = line === '' ? ' ' : line |
| 494 | nodes.push( |
| 495 | <span |
| 496 | key={nextKey()} |
| 497 | fg={palette.codeTextFg} |
| 498 | bg={palette.codeMonochrome ? undefined : palette.codeBackground} |
| 499 | > |
| 500 | {displayLine} |
| 501 | </span>, |
| 502 | ) |
| 503 | if (index < lines.length - 1) { |
| 504 | nodes.push('\n') |
| 505 | } |
| 506 | }) |
| 507 | |
| 508 | nodes.push('\n\n') |
| 509 | return nodes |
| 510 | } |
| 511 | |
| 512 | const renderBlockquote = ( |
| 513 | blockquote: Blockquote, |